I am trying to change the opacity of an element after every 100 milliseconds after a click event. But it is not working. The function change is called after a click event. Here is my code:
function change (i) {
var o:number = 0;
setTimeout( function() {
o = o + 0.1;
document.querySelector("div.label").style.opacity = o;
console.log("o = " + o);
}, 100)
}
When I console log, the value of o is always 0.1. What is wrong with this code?
document.querySelector("div.label")with react. Prefer the use ofrefanduseEffect(or maybeuseLayoutEffect)