【发布时间】:2018-01-15 01:35:42
【问题描述】:
我希望能够做到这一点:
import styles from 'switchstyle.css';
const Choice = function (props) {
const cssClasses = [];
if (props.active) {
// i think .active would be defined in the css file
cssClasses.push(style.active);
}
return (
<div
onClick={props.onClick}
className={cssClasses}
>
{props.label}
</div>
);
};
我在 React 书中看到过类似的东西,但我无法让它工作——我想我缺少一些 webpack 插件(我猜)。谢谢
【问题讨论】:
-
为什么您没有为过去的任何问题标记正确答案?它可以帮助其他人在搜索时找到正确的答案。请务必点击正确答案旁边的空白复选标记。
-
@alernerdev 什么不起作用?