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);