|
|
|
|
|
by Izkata
234 days ago
|
|
That's wrong, it's calling setAge immediately and not making a callback. You'll get an infinite render loop from that. It should be: const handleAgeChange = () => setAge((prevAge) => prevAge + 1);
https://react.dev/reference/react/useState#updating-state-ba...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. |
|