我有一个处理更改文本字段的函数:
private handleNameChange(e: React.FormEvent<FormControl>) {
const name = e.target.value;
this.setState({ name });
this.props.editGroupName(name);
}
这是连接到FormControl的onChange:
<FormControl type='text' placeholder='Name' value={this.state.name} onChange={this.handleNameChange} />
然而,根据TypeScript,这是错误的:
TS2339: Property 'value' does not exist on type 'EventTarget'.
我也尝试过使用currentTarget
。我该如何解决这个问题?
答案 0 :(得分:2)
尝试将e: React.FormEvent<FormControl>
替换为e: React.FormEvent<FormControlProps>
。