我正在使用类名向 React 组件添加许多类。在我的按钮中,如果我愿意,我希望有机会向组件添加一个类,它应该是可选的。
我怎样才能摆脱错误?
按钮代码
import classnames from "classnames";
import styles from "./button.module.css";
interface ButtonProps {
children: JSX.Element;
onClick: () => void;
small?: boolean;
className?: string;
}
function Button({ onClick, children, small, className }: ButtonProps) {
return (
<button
className={classnames(styles.button, {
[styles.small]: small,
[className]: !!className,
})}
onClick={onClick}
>
{children}
</button>
);
}
export default Button;
和错误:
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)