JSFiddle - React, Tailwind, and code Playground
HTML
<script src=""https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js""></script>
<input id="input" type='text' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
JavaScript
var _changeInterval = null;
$("#input").keyup(function() {
console.log("wait I am still typing, clear my previous Interval, If any exists")
// wait untill user type in something
// Don't let call setInterval - clear it, user is still typing
clearInterval(_changeInterval)
_changeInterval = setInterval(function() {
console.log("User finished typing, clear interval again. We don;t want to repeat our task for indefinitely")
// Typing finished, now you can Do whatever after 2 sec
clearInterval(_changeInterval)
console.log("now search")
}, 2000);
});