[英]Type 'void' is not assignable to type '((event: ChangeEvent<HTMLInputElement>) => void) React TypeScript
Im a beginner in React Typescript, and I have defined some props is a .JS file that I want to use in a .tsx file.我是 React Typescript 的初学者,我已经定义了一些道具是我想在.tsx文件中使用的.JS文件。 but I receive this error on one of my TypeScript lines:但我在我的 TypeScript 行之一上收到此错误:
<MyTextField style={{width:'60%'}} name='ActivationDate' type='date' defaultValue={values1.ActivationDate} onChange={handleChange('ActivationDate')}/>
Type 'void' is not assignable to type '((event: ChangeEvent<HTMLInputElement>) => void) | ((event: ChangeEvent<HTMLSelectElement>) => void) | ((event: ChangeEvent<HTMLTextAreaElement>) => void) | undefined'.
The CodeSandbox contains both my JS file and TSX file: https://codesandbox.io/s/tsx-rj694 CodeSandbox 包含我的 JS 文件和 TSX 文件: https://codesandbox.io/s/tsx-rj694
what seems to be the problem and how can I write this correctly?似乎是什么问题,我怎样才能正确地写这个?
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => handleChange(e.target.value)}
I assume you are not passing the event object into the handleChange
method.我假设您没有将事件 object 传递给handleChange
方法。
This is how you should amend your onChange
event handler:这是您应该修改onChange
事件处理程序的方式:
onChange={() => handleChange('ActivationDate')}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.