JSFiddle - React, Tailwind, and code Playground

HTML

<div id="widget"></div>

JavaScript

var timer;
				var params={};
        params.color='light';
        $(document).ready(function () {            
            timer=createInterval(showSmallWidget, params.color, 500);
        });
		
        function createInterval(f, dynamicParameter, interval) {
            setInterval(function () {
                f(dynamicParameter);
            }, interval);
        }
	
        function showSmallWidget(color) {
            if ($('#widget').html() == '') {
                //do stuff
            }
            else {
                alert('else. timer=' + timer);
                if (timer) { console.log('CLEAR TIMER'); timer.clearInterval(); timer = null; }
            }
        }