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
Explanation:
When not using useDistinct, every call to setState will rerender the component. Even if you call setState(state).
When using useDistinct, it should check for === equality. Or you can provide a custom comparison function which does the equality check.
The text was updated successfully, but these errors were encountered:
@benneq I'm unable to reproduce the use case you provided- it only logs "rendered" once, even after I pressed the button. For reference, I'm using react 16.8.6.
I'd like to have some
useDistinct
hook, which takes a value (or another hook) and only changes state if the returned value has changed.It's kinda the opposite way of
useMemo
. It should rerender based on output instead of input value.I'm not sure if that's possible at all...
Usage:
Explanation:
When not using
useDistinct
, every call tosetState
will rerender the component. Even if you callsetState(state)
.When using
useDistinct
, it should check for===
equality. Or you can provide a custom comparison function which does the equality check.The text was updated successfully, but these errors were encountered: