【发布时间】:2021-10-16 18:54:42
【问题描述】:
基本上我正在关注这个tutorial,将其转换为 React 和 TypeScript
这是我为 onSubmit 事件编写的代码
const signUp = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
// Problematic lines of code
const email = event.target[0].value;
const password = event.target[1].value;
};
以及基本的注册表单
return (
<div>
<form id="signUp" onSubmit={signUp}>
<h3>Sign up</h3>
<label>Email </label>
<input type="email" name="email" />
<label>Password </label>
<input type="password" name="password" />
<br></br>
<input type="submit"></input>
</form>
</div>
)
完整的错误:
Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'EventTarget'.
Property '0' does not exist on type 'EventTarget'. TS7053
【问题讨论】:
标签: javascript reactjs typescript react-hooks tsx