我有一个按钮组件,正在尝试使用它编写道具类型,type
并且在控制台中看到此错误。谁能帮忙吗?
Type '{ children: string; label: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'onClick' does not exist on type 'IntrinsicAttributes & Props'. TS2322
我的代码摘录
type Props = {
label: string;
children: ReactNode;
};
const Button = ({ label, children, ...props }: Props) => (
<button label={label} {...props}>
{children}
</button>
);
您需要添加onClick
到Props
这样的:
type Props = {
label: string;
children: ReactNode;
onClick: () => void;
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句