const [ready, set_ready] = useState(false);
...
if (condition === true) {
set_ready(true);
}
The code above causes infinite loop.
But if I changed it to
if (condition === true && !ready) {
set_ready(true);
}
The the problem is fixed.
This means that setting the ready
useState to its current value triggers re-render.
This does not make sense.
Can anyone explain?