JSFiddle - React, Tailwind, and code Playground

by Julien Etienne

JavaScript

// Setup a timer
var timeout;

// Listen for resize events
window.addEventListener('click', function ( event ) {

	console.log( 'no debounce' );

	// If there's a timer, cancel it
	if (timeout) {
		window.cancelAnimationFrame(timeout);
	}

    // Setup the new requestAnimationFrame()
	timeout = window.requestAnimationFrame(function () {

        // Run our scroll functions
		console.log( 'debounced' );

	});

}, false);