我想简短地用一个数组重构我的const声明。 来自:
const primaryStyling = {
className: classNames(
'button-primary',
className,
)
};
const secondaryStyling = {
className: classNames(
'button-secondary',
className,
)
};
const successStyling = {
className: classNames(
'button-success',
className,
)
};
类似于:
const styles = ['primary', 'secondary', 'success', 'info'];
styles.map(style => (
const `button-${style}` = {
className: classNames(
'button-primary',
`button-${style}`,
className,
)
};
))
但当然,它没有那样工作......这可能吗?