JSFiddle - React, Tailwind, and code Playground
by asdf
HTML
<input type="text" />
JavaScript
// If you were building a search tool and wanted search results to pop up as you typed but the server call was taxing, write a function that gets called on every key down but calls the server when the user stops typing for 400ms.
function sendRequest() {
var timeout;
return function (e) {
clearTimeout(timeout);
timeout = setTimeout(doSendRequest, 400, e);
}
}
function doSendRequest(e) {
console.log(e.target.value);
}
document.querySelector('input').addEventListener('input', sendRequest());