0
这里是我的功能:如何引用reactjs/JSX中的局部变量?
import styles from '../common.css'
class A extends Component {
...
renderBtn(expanded) {
let btnStyle = expanded ? 'icon-circle-up' : 'icon-circle-down'
return (
<button className={`$styles.icon $btnStyle`}> Hi</button>
);
}
}
不知何故,HTML出来是这样的:
<button class='_dqwdqweqwefvasdasdas $btnStyle'> Hi</button>
$btnStyle
上面没有解决存储在变量btnStyle
值。
我怎样才能使它工作?
'$ styles'来自上面的'import styles ...'行。我需要保留这个 –
className = {$ styles.icon +“”+ btnStyle} dint的工作? –