-
Notifications
You must be signed in to change notification settings - Fork 212
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
Voting: use aragonAPI for React + React hooks #717
Conversation
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'm not sold on migrating App.js
to use hooks completely.
I like it for simple components without too much logic, but for the main state container and logic controller of an app (which usually has no use for lifecycle hooks), it feels more difficult to read and understand due to everything being declared in-place without a lot of syntactic separation.
Particularly tricky is the dependencies lists, which looks likely to bite us at one point or another.
voting-app.js now contains most of the logic of the app. Other changes: - Remove vote-hooks.js: usePromise() is now in utils-hook.js, and the rest is in voting-app.js - Remove provideNetwork (replaced by useNetwork() from @aragon/api-react) - Replace the provideSettings HOC by a useSettings() hook. - Refactor IdentityManager.js to expose a hook rather than a context. - Remove app-hooks.js and app-contexts.js (made useless by specialized hooks / providers like SettingsProvider / useSettings() and IdentityProvider / useIdentity()).
Since it contains more than a component.
@@ -31,6 +26,8 @@ | |||
"jsxBracketSameLine": false | |||
} | |||
], | |||
"react-hooks/rules-of-hooks": "error", |
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.
Nice!
- Stop prerendering the vote texts (and only rerender them when needed). - Move the vote-related hooks into vote-hooks.js (rather than app-logic.js). - Move usePanelState() into utils-hooks.js.
prevVote.numData.votingPower === nextVote.numData.votingPower && | ||
prevVote.numData.yea === nextVote.numData.yea && | ||
prevVote.numData.nay === nextVote.numData.nay | ||
) |
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.
@sohkai now 1000x faster 😆
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.
One last small thing and I think this is good to go ⚡️!
The app is now using aragonAPI for React, and has also been a bit rearranged to take advantage of using React Hooks. The idea is to keep using the Voting app as an experiment to find and validate patterns related to React Hooks that we could use. A new file, `app-logic.js`, contains most of the logic to be used by `App.js`, by exporting `AppLogicProvider` and `useAppLogic()`. This is meant to be the pattern used by other apps in the future (providing that we validate this idea). Other changes: - VotingCard now skips any unnecessary update. - The vote texts (description and metadata) are now a separate component rather than being pre-rendered (that way it is easier to skip updates).
See aragon/aragon.js#259