I have a button component in which I’m trying to write the prop types using type and I see this error in the console. Could anyone please help?
Type '{ children: string; label: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'onClick' does not exist on type 'IntrinsicAttributes & Props'. TS2322
Excerpt from my code
type Props = {
label: string;
children: ReactNode;
};
const Button = ({ label, children, ...props }: Props) => (
<button label={label} {...props}>
{children}
</button>
);
Advertisement
Answer
You need to add onClick into Props like:
type Props = {
label: string;
children: ReactNode;
onClick: () => void;
};