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

Change ProposalsList component to a functional component #2448

Merged
merged 17 commits into from
Apr 3, 2020

Conversation

vctt94
Copy link
Member

@vctt94 vctt94 commented Mar 17, 2020

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.

@vctt94 vctt94 changed the title Change ProposalsList component to a functional component [WIP] Change ProposalsList component to a functional component Mar 17, 2020
@vctt94 vctt94 force-pushed the fetch-state-machine branch 3 times, most recently from d8e4559 to 4564dc0 Compare March 19, 2020 00:50
@vctt94 vctt94 changed the title [WIP] Change ProposalsList component to a functional component Change ProposalsList component to a functional component Mar 20, 2020
Copy link
Member

@matheusd matheusd left a 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

const { location, uiAnimations } = useSelector(state => ({
location: sel.location(state),
uiAnimations: sel.uiAnimations(state)
}));
Copy link
Member

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);

Copy link
Member Author

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.

Copy link
Member

@matheusd matheusd left a 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?

@vctt94
Copy link
Member Author

vctt94 commented Mar 31, 2020

I am making changes at proposal details at #2449

@alexlyp alexlyp merged commit 6ebcf10 into decred:master Apr 3, 2020
@vctt94 vctt94 deleted the fetch-state-machine branch April 16, 2020 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants