JSFiddle - React, Tailwind, and code Playground
JavaScript
const intervalFn = (mount) => {
const closedVariable = 0;
if (mount)
setInterval(() => {
setClosedVariable(closedVariable + 1)
}, 1000)
}
function setClosedVariable(num) {
closedVariable = num;
console.log(closedVariable);
intervalFn(false);
}
intervalFn(true);
// prints incremented closed variable as expected
// closedVariable is correctly updated