detect if typing stop react code example
Example: react search when stop typing
const [inputValue, setInputValue] = useState('');
const [typingTimeout, setTypingTimeout] = useState(0);
const doSearch = () => {
// search
};
const handleInputChange = e => {
if (typingTimeout) {
clearTimeout(typingTimeout);
}
setInputValue(e.target.value);
// Start searching after 0.5 seconds
setTypingTimeout(setTimeout(doSearch, 500));
}
return (
<input value={inputValue} onChange={handleInputChange} />
);