classnames
参考资料 - https://github.com/JedWatson/classnames
Usage with React.js
This package is the official replacement for classSet, which was originally shipped in the React.js Addons bundle.
这个包是 classSet 的正式代替,classSet 是最初应用于 reactjs 的扩展包。
One of its primary use cases is to make dynamic and conditional className props simpler to work with (especially more so than conditional string manipulation). So where you may have the following code to generate a className prop for a in React:
其中的主要用法是把 classname 设置成动态的以及可条件变化的。
举个栗子,最常见的写法实现 button 样式的可变化:
class Button extends React.Component {
// ...
render () {
var btnClass = 'btn';
if