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的工作? –