当用户停止输入时,我需要执行搜索.我知道我应该用setTimeout().但是对于Reactjs I cant find how it works.,有人能告诉我,当用户停止输入几秒钟(假设5秒钟)时,如何调用一个方法(处理搜索).我不知道该在哪里编写代码来判断用户是否已停止键入.
import React, {Component, PropTypes} from 'react';
export default class SearchBox extends Component {
state={
name:" ",
}
changeName = (event) => {
this.setState({name: event.target.value});
}
sendToParent = () => {
this.props.searching(this.state.name);
}
render() {
return (
<div>
<input type="text" placeholder='Enter name you wish to Search.' onChange={this.changeName} />
</div>
);
}
}
我想在用户停止键入时调用sendToParent方法.