react search when stop typing

Solutions on MaxInterview for react search when stop typing by the best coders in the world

showing results for - "react search when stop typing"
Diego Alejandro
23 Jun 2019
1const [inputValue, setInputValue] = useState('');
2const [typingTimeout, setTypingTimeout] = useState(0);
3
4const doSearch = () => {
5  // search
6};
7
8const handleInputChange = e => {
9  if (typingTimeout) {
10    clearTimeout(typingTimeout);
11  }
12  setInputValue(e.target.value);
13  // Start searching after 0.5 seconds
14  setTypingTimeout(setTimeout(doSearch, 500));
15}
16
17return (
18  <input value={inputValue} onChange={handleInputChange} />
19);