JSFiddle - React, Tailwind, and code Playground

by acbabis

HTML

<input class="foo">

JavaScript

const input = document.querySelector('input.foo');

let ready = true;
let h;
input.addEventListener('input', (event) => {
	const { value } = event.target;
	if(ready) {
  	handle(value);
    ready = false;
    const delay = () => {
      setTimeout(() => {
        if(h) {
          h();
          h = null;
          delay();
        } else {
        	ready = true;
        }
      }, 500);
    }
    delay();
  } else {
  	h = () => handle(value);
  }
});

function handle(value) {
	console.log(+new Date(), value);
}