React state hook that returns the previous state.
As described here (legacy): https://legacy.reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
Just like usePrevious but it will only update once the value actually changes. This is important when other hooks are involved and you aren't just interested in the previous props version, but want to know the previous distinct value
The usePrevious
hook is a useful tool for tracking the previous value of a variable in a functional component. This can be particularly handy in scenarios where it is necessary to compare the current value with the previous one, such as triggering actions or rendering based on changes.
Run the following command:
Now: 0, before:
Now: 0, before: Unrelated: 0