
[英]How to fix error type void is not assignable to type using react and typescript?
[英]How to fix the Type ‘{handleIndex: ()=> void}’ is not assignable to type 'IntrinsicAttributes' with TypeScript and React?
我是 Typescript 的新手,所以我不知道为什么会发生这个错误以及如何解决它......这是我的代码。
export default function SignupPage() {
const [index, setIndex] = useState<number>(0);
const handleIndex = () => {
setIndex(index + 1);
};
return (
<div>
<BasicInfo handleIndex={handleIndex} /> // error
</div>
);
}
我想将handleIndex
函数作为BasicInfo
组件的道具传递,但出现此错误:
Type ‘{handleIndex: ()=> void}’ is not assignable to type 'IntrinsicAttributes'.
我能做些什么呢?
看到您的BasicInfo
组件,我可以看到它不需要任何道具。 您应该将 handleInfo 添加到道具:
function BasicInfo({handleIndex}) {...}
问题未解决?试试以下方法:
如何使用 TypeScript 和 React 修复类型“{handleIndex: ()=> void}”不可分配给类型“IntrinsicAttributes”?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.