我能够在我的简单 React 应用程序中实现一个事件处理程序,并且我想更深入地了解 event.target.value。我有一个猜测,但我想询问其他人,以便我可以确认或修改任何错误的理解。
那么...我们如何才能在 React 中使用 event.target.value 呢?事件是否属于我在此处找到的 Event Web API?或者它更像是一个 React 的东西?
这是我的代码供参考
import React from 'react';
import Display from './Display';
export default class Search extends React.Component{
constructor(props){
super(props);
this.state = { userInput: '' };
this.onSubmit = this.onSubmit.bind(this);
this.updateInput = this.updateInput.bind(this);
}
updateInput(e){
this.setState({userInput: e.target.value});
}
onSubmit(){
const title = this.state.userInput;
console.log(title)
}
render(){
return(
<div>
<label>
Movie Search App
<br></br>
<input type="text" value={this.state.userInput} onChange={this.updateInput}/>
</label>
<br></br>
<input type="submit" value="Search" onClick={this.onSubmit}/>
<Display />
</div>
)
} …
Run Code Online (Sandbox Code Playgroud)