您能否以简单的方式向我解释在React代码中使用Classnames实用程序的目的是什么?我刚读类名的文档,但我还不能掌握什么是使用它的代码,像这样的主要原因:为什么以及如何在React组件中使用classnames实用程序?
import classnames from 'classnames';
[...]
render() {
const { className } = this.props
return (
<div className={classnames('search', className)}>
<div className="search-bar-wrapper">
<form className="search-form" onSubmit={this.onSearch.bind(this)}>
<div className="search-bar">
<label className="screen-reader-only" htmlFor="header-search-form">Search</label> [...]
这段代码的完整版(JSX): https://jsfiddle.net/John_Taylor/j8d42m2f/2/
我不明白什么是在这行代码会:
<div className={classnames('search', className)}>
我也读了( how to use classnames library for React.js)的答案,但我仍然有了解我的代码问题片段。