您能否以簡單的方式向我解釋在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)的答案,但我仍然有了解我的代碼問題片段。