Skip to content
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

Merged

Conversation

Projects
None yet
2 participants

bpierre added some commits May 9, 2019

@bpierre bpierre requested a review from sohkai May 9, 2019

@bpierre bpierre referenced this pull request May 9, 2019

Merged

Eslint: add hook rules #771

@@ -42,8 +45,6 @@ const LocalIdentities = ({
return <EmptyLocalIdentities onImport={onImport} />
}

const { identityEvents$ } = React.useContext(IdentityContext)
const { showLocalIdentityModal } = React.useContext(LocalIdentityModalContext)

This comment has been minimized.

Copy link
@sohkai

sohkai May 9, 2019

Member

I wanted to avoid making this change until after #768 was merged, so we don't have too many conflicts :).

This comment has been minimized.

Copy link
@bpierre

bpierre May 9, 2019

Author Member

Reverted 👍

Revert "Always call hooks"
This reverts commit 68f0749.
},
[setDirection, _setStep, step]
[steps]

This comment has been minimized.

Copy link
@sohkai

sohkai May 9, 2019

Member

Do we not need to include the reducer's updateStep because it'll never change?

This comment has been minimized.

Copy link
@bpierre

bpierre May 9, 2019

Author Member

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

@bpierre bpierre changed the title Eslint add hook rules dependencies fix useSteps(): only update setStep when needed May 9, 2019

@sohkai

sohkai approved these changes May 9, 2019

Copy link
Member

left a comment

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 :(

@bpierre

This comment has been minimized.

Copy link
Member Author

commented May 9, 2019

Awesome, sounds like we've learned something new about hooks :).
Yes! 👍

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.

@bpierre bpierre merged commit 3912081 into eslint-add-hook-rules May 9, 2019

2 of 7 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/travis-ci/push The Travis CI build failed
Details
lint lint
Details
build build
Details
License Compliance FOSSA is analyzing this commit
Details
install install
Details
license/cla Contributor License Agreement is signed.
Details

@bpierre bpierre deleted the eslint-add-hook-rules--dependencies-fix branch May 9, 2019

@sohkai

This comment has been minimized.

Copy link
Member

commented May 9, 2019

Sounds reasonable to have a hooks/ folder to hold all the hooks

sohkai added a commit that referenced this pull request May 14, 2019

Eslint: add hook rules (#771)
* Add eslint rules for react-hooks
* useSteps(): only update setStep when needed (#774)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.