JSFiddle - React, Tailwind, and code Playground
JavaScript
$(function() {
var resizeTimer, width;
var mobile = tablet = desktop = false;
$(window).resize(function() {
// clear the timeout
clearTimeout(resizeTimer);
// execute breakpointChange() once the viewport
// has stopped changing in size for 400ms
resizeTimer = setTimeout(breakpointChange(), 400);
});
function breakpointChange() {
width = window.innerWidth;
if (!mobile && width < 400) {
tablet = desktop = false;
mobile = true;
console.log('is mobile');
}
if (!tablet && width > 401 && width < 768) {
mobile = desktop = false;
tablet = true;
console.log('is tablet');
}
if (!desktop && width > 769) {
mobile = tablet = false;
desktop = true;
console.log('is desktop');
}
}
$(window).resize();
});