[英]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.