|
|
|
|
|
by ascagnel_
240 days ago
|
|
You can actually further simplify the functional component by using setState's callback form. You don't always need to do this, but it makes setting state from within a useEffect much safer in that it won't need the current state value in its dependency array. const handleAgeChange = setAge((prevAge) => prevAge + 1);
|
|
The callback version is really only needed if there's a risk of setAge being called multiple times between renders and you do actually want all the mutations, vs only wanting it based on what's currently rendered.