What difference, if any, is there between the following two ways of setting state (functional react, of course)
setState(state + 5) setState((current) => current + 5)
I’ve been having a hard time finding a real solid answer on this….
I understand that if more complex logic was required, you’d have to go the anonymous function route to get multiple lines of code, but even then it’s not guaranteed. I read in the class-based state information on the React docs that there is never a guarantee of when it’s going to run because it’s asynchronous.
I had never seen (or used) a function as the argument on setState before seeing it in a tutorial recently and just wanted to find out if it had any differences at all.