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

fix: update stale state in reducer #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

exuanbo
Copy link

@exuanbo exuanbo commented Sep 7, 2024

Similar to facebook/react#25968

The reducer is used for memoization, not managing state. So I think it's ok to mutate the tuple, since the reducer is already not a pure function.

Copy link

codesandbox-ci bot commented Sep 7, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dai-shi
Copy link
Member

dai-shi commented Sep 7, 2024

Isn't it just a little optimization to avoid calling the selector in an edge case.

If it can cause a bug, can you create a test case please?

Hm, looking at facebook/react#25968, it's a bit different from ours. We don't have a memoized value, and useReducer works without memoizing the selector.

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.

2 participants