I am trying to understand why using the previous state to update the state of an element in React is preferred over using the current state. I have seen this practice being used in various code examples and tutorials, but I couldn't find a satisfying example that clearly explains the reasoning behind it.
I understand that updating the state using the previous state ensures that the correct state is used for the update and avoids race conditions, but I am still not clear on the details.
Can someone please provide a clear and concise explanation, along with a simple code example that demonstrates the difference between updating the state using the current state vs the previous state? I would appreciate any resources or references that can help me understand this better. Thank you.