![](/img/trans.png)
[英]TypeScript Property 'navigation' is missing in type but required in type 'Props' React Native
[英]Add type for onClick property which is in …props in React TypeScript
我有一个按钮组件,我正在尝试使用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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.