I am trying to update the value of stateValue with the value of i in setInterval but it changes only the value of i and doesn't update the stateValue in setInterval.
fun1 = () => {
let i = 0;
let intervalId = setInterval(() => {
console.log("i:", i);
this.setState({
stateValue: i
});
i = i + 1;
if (i === 3) {
i = 0;
}
console.log("stateValue:", this.state.stateValue);
}, 5000);
};