typing problem storeApi outside of react with immer middleware
See original GitHub issue@kurosh-z Hey, I fixed it recently. Please check the example in #169. If it doesn’t work, would you please file a new issue?
_Originally posted by @dai-shi in https://github.com/react-spring/zustand/issues/75#issuecomment-684075606_
Hi , #169 actually solved the typing problem inside of react. But if you use the setState api outside of react, typescript requires you to return the state.
// outside of react
useStore.setState((state) => {
state.bb.b1 = true;
});
codeSandbox :
https://codesandbox.io/s/pedantic-flower-immerzustand-forked-ptso7?file=/src/App.tsx
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Adding persist middleware to zustand store - Stack Overflow
https://github.com/pmndrs/zustand#middleware. you can find it under How to pipe middlewares const createStore = pipe(persistor, devtools, ...
Read more >Persist middleware - Zustand Documentation
The persist middleware enables you to store your Zustand state in a storage (e.g. localStorage , AsyncStorage , IndexedDB , etc.
Read more >Redux Essentials, Part 8: RTK Query Advanced Patterns
If we want to fetch the list of users outside of React, ... The actual caching reducer and middleware that we originally added...
Read more >Simplify and standardize your Redux configuration with Redux ...
Are you using Redux to manage state in your React application, ... using the Immer library; Support for async thunk out of the...
Read more >Stop Overcomplicating your State – Try Zustand
... Equality Middleware Store... Tagged with zustand, webdev, react, redux. ... We can create middleware to allow us to use immer easily.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let me close this issue as the first question is answered and now the context is a bit changed.
I added the above immer snippet in readme.md.
Ah, the codesandbox example in my comment. Here’s the fixed version: https://codesandbox.io/s/pedantic-flower-immerzustand-forked-5zdy9
The immer middleware with types:
It’s a long story (also discussed in various TS issues), but that’s how it works.