-
Notifications
You must be signed in to change notification settings - Fork 121
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
Change ProposalsList component to a functional component #2448
Conversation
d8e4559
to
4564dc0
Compare
0d3a70a
to
1db56fc
Compare
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.
Hooks seem interesting and definitely an improvement by removing the boilerplate connectors.
For reference for other reviewers, these are the main docs concerning hooks for react and redux (respectively):
https://reactjs.org/docs/hooks-overview.html
https://react-redux.js.org/api/hooks
app/components/layout/TabbedPage.js
Outdated
const { location, uiAnimations } = useSelector(state => ({ | ||
location: sel.location(state), | ||
uiAnimations: sel.uiAnimations(state) | ||
})); |
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.
As far I as can understand react hooks so far, this causes unnecessary renders.
See https://react-redux.js.org/api/hooks#equality-comparisons-and-updates
Specifically, given the selector function creates a new object every time it's run, it will always force a re-render.
I believe the correct way for this is to rewrite as
const location = useSelector(sel.location);
const uiAnimations = useSelector(sel.uiAnimations);
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.
Thanks for reference the docs, my bad not referencing it.
You are right, as we can see here: Call useSelector() multiple times, with each call returning a single field value
Change made.
ad7288e
to
0b76601
Compare
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.
Seems reasonable. One note though, the header is missing once you open a proposal. Is that correct?
I am making changes at proposal details at #2449 |
This PR depends on #2445 is a POC for #2438
It switches the Proposals component to use hook instead. I liked that approach, because with that, we can completely remove our connectors and improve our reducers, selectors and actions. A work toward: #1558.
I am also adding a fetch-state-machine using the xstate lib. This way we can get rid off the isLoading variable and properly treat states.