JSFiddle - React, Tailwind, and code Playground

by BurpmanJunior

HTML

<input id="target" type="text" placeholder="Text input" />

JavaScript

/**
 * Temp debounce text input
 */
function debounce(func, wait, immediate) {
    var timeout; // Init timeout
    return function () {
        var context = this, // Scope
            args = arguments; // Function args
        var later = function () {
            timeout = null;
            if (!immediate) func.apply(context, args);
        };
        var callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
    };
};

var t = document.getElementById('target');
var passInput = debounce(function(){
    console.log(t.value);
}, 800);
t.addEventListener('keyup', passInput);