we are talking about functional components having useState
lets say
const [age, setAge] = useState(0)
now let us say while updating age
I have to use the previous age
React docs mention something called FUNCTIONAL UPDATES where you can pass a function and the argument to that will be the previous value of the state, eg.
setState((previousAge) => previousAge + 1)
why do I need to do this when I can just do
setState(previousAge + 1)
what are the benefits of using functional setState
,
I know in class-based components there was something called batching of state updates in the functional way, but I can't find anything like that in functional components documentation.