xxxxxxxxxx
//if some of your code depends on that state update you can use a useeffect like this
useEffect(() => {
if (currentProgress[index].progress === 100) {
GoBack()
}
}, [currentProgress])
xxxxxxxxxx
/* React’s setState and useState do not make changes directly to the state
object. Instead, they create queues for React core to update the state object
of a React component. So the process to update React state is asynchronous for
performance reasons. That’s why changes don’t feel immediate */
/* SOLUTION: However, you can use the useEffect hook to update the state
immediately in a functional component. */
import React, { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(count + 1);
};
useEffect(() => {
console.log(count);
}, [count]);
return <button onClick={handleClick}>Click me</button>;
}
/* Now the console.log statement will log the updated state value, because it
is being called inside the useEffect function with the count state variable in
the dependency array. */