I need to run something when the user finishes typing, when the timer finishes basically. Timer is being reset when user is typing but once time is over, it will run the function for as many times as the user typed
export default function SearchMovie() {
var keyUpTimer = 0;
const keyUpTimerDelay = 2000;
const handleOnKeyUp = (event) => {
clearTimeout(keyUpTimer);
keyUpTimer = setTimeout(() => {
console.log(input);
}, keyUpTimerDelay);
};
return (
<div className="search-container">
<input
type="text"
className="input-text"
onInput={(e) => setInput(e.target.value)}
onKeyUp={handleOnKeyUp}
placeholder="Type a movie to search..."
/>
</div>
);
}