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?
JavaScript
x
3
1
Type '{ children: string; label: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & Props'.
2
Property 'onClick' does not exist on type 'IntrinsicAttributes & Props'. TS2322
3
Excerpt from my code
JavaScript
1
11
11
1
type Props = {
2
label: string;
3
children: ReactNode;
4
};
5
6
const Button = ({ label, children, props }: Props) => (
7
<button label={label} {props}>
8
{children}
9
</button>
10
);
11
Advertisement
Answer
You need to add onClick
into Props
like:
JavaScript
1
6
1
type Props = {
2
label: string;
3
children: ReactNode;
4
onClick: () => void;
5
};
6