-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useSteps(): only update setStep when needed #774
useSteps(): only update setStep when needed #774
Conversation
@@ -42,8 +45,6 @@ const LocalIdentities = ({ | |||
return <EmptyLocalIdentities onImport={onImport} /> | |||
} | |||
|
|||
const { identityEvents$ } = React.useContext(IdentityContext) | |||
const { showLocalIdentityModal } = React.useContext(LocalIdentityModalContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid making this change until after #768 was merged, so we don't have too many conflicts :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted :+1:
This reverts commit 68f0749.
}, | ||
[setDirection, _setStep, step] | ||
[steps] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to include the reducer's updateStep
because it'll never change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, setSomething
from useState()
and dispatch
from useReducer()
are both guaranteed to never update [1], and don’t need to be added to the dependencies list.
[1] Search for “guarantees” in these two sections:
https://reactjs.org/docs/hooks-reference.html#usestate
https://reactjs.org/docs/hooks-reference.html#usereducer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, sounds like we've learned something new about hooks :).
Although it's still baffling why the little hacks I was doing didn't work specifically for a single case of setting the steps to 1 :(
Yes and I’m not a big fan of the solution as it is… but at least the complexity stays in the hook itself, which is nice. Maybe we should move every custom hook in its own file, so that reducers, initial states etc. declared outside of the hook itself wouldn’t be in the same module than other hooks. |
Sounds reasonable to have a |
* Add eslint rules for react-hooks * useSteps(): only update setStep when needed (#774)
See https://github.com/aragon/aragon/pull/771/files/2907ecbbf266d6d866c874991de468a00fc49ddc#r282035502