JSFiddle - React, Tailwind, and code Playground

HTML

<input id='search' />

JavaScript

$('#search').keyup(function() {
    var string = $(this).val();

    if (string.length >= 2) {
        var elem = $(this);
        // save newest search
        elem.data('search',  string)
        // clear pending searches
        .clearQueue().stop()
        // waits
        .delay(2000)
        // runs search
        .queue(function() { 
            console.log(string); 
/*
            $.ajax({
                'type': 'GET',
                dataType: 'html',
                'url': url,
                'success': function(data) {

                    // check if can be run
                    if (elem.data('search') != search) return;

                    // show the search data
                }
            });*/
            if (elem.data('search') !=  string) return;
        });
    } else if (string.length <= 1) {
        // restore page content as of when it was loaded
    }
});