-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[v5]: follow React "standard" way with breaking behavioral change #2395
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,9 @@ const useBearStore = create<BearStoreState & BearStoreAction>((set) => ({ | |
})) | ||
|
||
function Counter() { | ||
const { bears, increasePopulation } = useBearStore( | ||
({ bears, increasePopulation }) => ({ | ||
bears, | ||
increasePopulation, | ||
}), | ||
Comment on lines
-22
to
-26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say it worked before by chance. This selector creates a new object every time, which isn't supported in v5. We should use a memoized selector, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, was this test intentional to check the behavior with such selectors? @TkDodo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I think I copied this way if creating a store from somewhere. Definitely not intentional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for confirming. That was the reason I introduced |
||
const bears = useBearStore(({ bears }) => bears) | ||
const increasePopulation = useBearStore( | ||
({ increasePopulation }) => increasePopulation, | ||
) | ||
|
||
useEffect(() => { | ||
|
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.
This behavior (inline selector optimization) isn't supported in v5. Use
zustand/traditional
.