You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If i have other hooks in a component that are unrelated to what the usePrevious is tracking, some update that causes a rerender from that hook will sync the previous value to the current value. To see an example of this, here's a sandbox. To see the behavior, click + a few times and then click toggle on to toggle unrelated state. Not that the value for prev will update.
In this sandbox I've implemented an alternative usePrevious that tracks a more accurate version of previous.
I can make a PR but wanted to know if maybe we call this new version something else to support the previous version of usePrevious.
I understand that usePrevious tracks the previous render value, but this version may be more strictly useful in an application. Maybe usePreviousDistinct?
The text was updated successfully, but these errors were encountered:
Oh! I knew I've been wanting this hook without even knowing how to think about it. I just saw it pop in my VSCode autocomplete and realized this was just what I needed!
If i have other hooks in a component that are unrelated to what the
usePrevious
is tracking, some update that causes a rerender from that hook will sync the previous value to the current value. To see an example of this, here's a sandbox. To see the behavior, click+
a few times and then clicktoggle on
to toggle unrelated state. Not that the value forprev
will update.In this sandbox I've implemented an alternative usePrevious that tracks a more accurate version of previous.
I can make a PR but wanted to know if maybe we call this new version something else to support the previous version of
usePrevious
.I understand that
usePrevious
tracks the previous render value, but this version may be more strictly useful in an application. MaybeusePreviousDistinct
?The text was updated successfully, but these errors were encountered: