The result of getSnapshot should be cached to avoid an infinite loop #1936
-
I'm new to zustand. I've got my basic functionality working, but I'm seeing this warning coming from
The stack trace is not very helpful, but I'm not directly using Is this a zustand bug or should I be scrutinizing my own code more? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 14 replies
-
Are you creating a fresh store in render function? |
Beta Was this translation helpful? Give feedback.
-
my suggestion would be to use "useShallow" Docs const [blah] = useMyStore(useShallow((state) => [state.blah])); |
Beta Was this translation helpful? Give feedback.
-
my case is |
Beta Was this translation helpful? Give feedback.
-
I'm having a similar issue after upgrading from 4.5.2 to 5.0.0 In my case I was doing:
I was able to confirm I tried useShallow and it didn't work. (still getting infinite loop error) I implemented a workaround by separating the accessors into different hooks:
I feel like pulling each variable individually is an unintended restriction though, and I'd personally prefer not to have to decide whether to use useShallow everytime FWIW |
Beta Was this translation helpful? Give feedback.
-
Similar case with useShallow here: I had this selector:
Worked fine on v4, but on v5 I need to use |
Beta Was this translation helpful? Give feedback.
-
I have same problem when upgrade to v5, v4 working greate |
Beta Was this translation helpful? Give feedback.
Thank you, I figured it out. The problem was that I was using
useX
callbacks to get around some eslint errors about the use ofuseX
hooks outside react components. The actual solution was: