I've made a simple component:
const CloseButton = ({ onClick }: { onClick: MouseEventHandler }) => {
const classes = useStyles();
return <CloseIcon className={classes.closeButtonStyles} onClick={onClick} />;
};
export default CloseButton;
Which I can call like:
<CloseButton onClick={handleClose} />
This works fine.
But when I add a className
attribute, eg:
<CloseButton className={classes.closeButton} onClick={handleClose} />
I get the error:
Type '{ className: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & { onClick: (event: MouseEvent) => void; }'. Property 'className' does not exist on type 'IntrinsicAttributes & { onClick: (event: MouseEvent) => void; }'
Why does this appear? Why is the className
attribute getting mixed up with the onClick
prop?
className
as a prop, you are assigning the classes usinguseStyles
– Matin KajabadiCloseIcon
defined? – wentjun