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

Unnecessary call to selectStateProps when using useSelector #22

Open
objectliteral opened this issue Dec 9, 2019 · 1 comment
Open
Assignees
Labels
bug Something isn't working performance Performance optimization

Comments

@objectliteral
Copy link
Contributor

objectliteral commented Dec 9, 2019

While working on #21 I found that the selectStateProps functions that are passed to useSelector, currently, get executed twice for each relevant key change. This is due to useSelector (which is already reading state using useState) always calling it once and the callback given to the store proxy calling it to detect changes; if changes are found, the callback sets the state resulting in the entire selectStateProps function to be executed again.

This should be fixed such that for each relevant store key change, selectStateProps is only called once.

The impact is probably not that huge since the return value of the two selectStateProps calls will always be the same, causing React to only trigger (at most) one rerender.

@objectliteral objectliteral added bug Something isn't working performance Performance optimization labels Dec 9, 2019
@objectliteral objectliteral self-assigned this Dec 9, 2019
@objectliteral
Copy link
Contributor Author

objectliteral commented Dec 11, 2019

I want to note here that my idea for solving this did not work and after extensive consideration I did not come up with a way to avoid these calls while at the same time causing all necessary updates to happen and without causing unnecessary rerenders.

Since the impact of this issue is not that big, I will prioritize others first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Performance optimization
Projects
None yet
Development

No branches or pull requests

1 participant