JSFiddle - React, Tailwind, and code Playground

HTML

Enter Text To Search :-
<input stype="text" id="search" />
<br/>After 2 seconds search will be fired on :- <span id="textTobeSearched"></span>

JavaScript

function debounce(fn, delay) {
    var timer = null;
    return function () {
        var context = this,
            args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    };
};

$('#search').keypress(function () {
    debounce(function (event) {

        console.log('Search keypress');
        var text = $('#search').val();

        $('#textTobeSearched').text(text);
    }, 2000);
});