dag*_*da1 1 javascript ecmascript-6 reactjs
任何人都可以建议一种方法来清理这个凌乱的classname结构:
const ButtonTemplate = props => {
const themed = `btn-${props.theme}`
const themedButton = `${styles[themed]} ${themed}${(props.disabled) ? ' disabled' : ''}}`
return (
<button className={`${styles.btn} ${themedButton}`} type='button' onClick={props.onClick}>{props.children}</button>
)
}
Run Code Online (Sandbox Code Playgroud)
关于什么
function ButtonTemplate({theme, disabled, onClick, children}) {
const themed = `btn-${theme}`;
return (
<button className={[
styles.btn,
styles[themed],
themed,
disabled ? 'disabled' : ''
].join(" ")} type='button' onClick={onClick}>{children}</button>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
109 次 |
| 最近记录: |