Search posts, tags, users, and pages
Karan Hejmadi
Full Stack Developer
Let's start by asking ourselves why would we need the previous state? There might be some cases where you need to render a different view which also changes the current state based on the previous state. Consider a simple example - you have an ON/OF...
paddingleft
How about - setCount(prevCount => prevCount + 1)}
You can do that as well. setCount(prevCount => prevCount+1) gets the previous state and adds 1 to it. I think it works better if you have several setState in batches.
paddingleft
How about - setCount(prevCount => prevCount + 1)}