How to make an input box which will give suggestion with small delay not on every character input fast. I don't want to hit suggestion api on every char input.
class Input extends React.Component {
constructor (props){
super(props);
this.state = {
inputVal:'',
suggestion : []
}
}
handleChange = ({target:{value}})=>{
fetch('https://api.github.com/search/users?q='+value, (res)=>{
this.setState({suggestions:res.items});
});
}
render(){
<input onChange={this.handleChange} value {this.state.inputVal} />
<ul id="suggestions">
this.state.suggestions.map(sugg=>{
return (
<li>{sugg.login}</li>
)
})
</ul>
}
}
ReactDOM.render(<Input />, document.getElementById('container'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id='container'></div>