Skip to content

Infinite loop with zustand@5.0.0-rc.1 #2716

Answered by dai-shi
Romainlg29 asked this question in Bug report
Discussion options

You must be logged in to vote

Thanks for reporting. Really great to see people try v5-rc.

I think it's the intentional change.
Please check this:

### Requiring stable selector outputs
There is a behavioral change in v5 to match React default behavior.
If a selector returns a new reference, it may cause infinite loops.
For example, this may cause infinite loops.
```js
// v4
const action = useMainStore((state) => {
return state.action ?? () => {}
})
```
The error message will be something like this:
```
Uncaught Error: Maximum update depth exceeded. This

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Romainlg29
Comment options

Answer selected by Romainlg29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants