I'm using classnames to add many classes to a React component. In my button I want to have the opportunity to add a class to the component if I want to, it should be optional.
But I get a type error, see attached image
How can I get rid of the error?
Button code
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;
and the error:
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)