I need some help. I am beginner in TS and i don't know how can i use my event props in my component. I defined two props and i need all my events as rest props.
I got an error when i use my component with onClick event.
Error: Property 'onClick' does not exist on type 'IntrinsicAttributes & ButtonProps'
I will be grateful for any help you can provide.
Here is my component:
export type ButtonProps = {
children: React.ReactNode;
className: string;
};
export const Button = ({ children, className, ...rest }: ButtonProps) => {
return (
<button className={className} {...rest}>
{children}
</button>
);
};
You can do it like this using PropsWithChildren
:
import { PropsWithChildren } from "react";
export type ButtonProps = {
className: string;
};
export const Button = ({ children, className, ...rest }: PropsWithChildren<ButtonProps>) => {
return (
<button className={className} {...rest}>
{children}
</button>
);
};