Questions tagged [zustand]

For questions regarding Zustand, a hook-based state management system for React.

A small, fast and scalable bearbones state-management solution using simplified flux principles. Has a comfy API based on hooks, isn't boilerplatey or opinionated.

231 questions
3
votes
2 answers

TypeScript Error with Zustand's Persist Middleware and StateCreator in React App

I'm trying to use Zustand's persist middleware to store and retrieve state in my React application. However, I'm encountering a TypeScript error that I'm struggling to resolve. The error message is as follows: Argument of type…
3
votes
2 answers

How to render components in NextJS 13 only on client

I'm working on a project at the moment which requires my components to react to frequently changing conditions on the client side, however NextJS 13 seems to be forcing server-side rendering as far as I can tell. I tried dynamic loading using import…
Marcus Horne
  • 363
  • 1
  • 5
  • 16
3
votes
1 answer

Zustand not persisting data in AsyncStorage correctly

I am trying to persist data to AsyncStorage using Zustand. Here is my code for the store: //store.ts export const useAuthStore = create( persist( (set) => ({ token: "", setToken: (token) => set((state) => ({ …
herbie
  • 335
  • 2
  • 14
3
votes
2 answers

Reset persisted stated of an application State managed with Zustand

I'm trying to remove all user data from the persisted state, when a user logs out. For managing my state I'm using Zustand and followed this guide: https://docs.pmnd.rs/zustand/guides/typescript I'm creating my store as follows: export const…
Robin
  • 8,162
  • 7
  • 56
  • 101
3
votes
3 answers

Zustand state with javascript Map is not updating

I am trying to use map to store state, while the state is updating, the components are not re-rendering with the new state const store = (set, get) => ({ items: new Map(), addItem: (key, item) => { set((state) => state.items.set(key,…
3
votes
0 answers

Zustand reset between tests pollutes tests when running in parallel with jest

I'm using zustand and jest - but have been running into some trouble with tests polluting each other. So I'm trying to reset the states/stores between each test. But I notice some issues between my test suites that could only be solved by yarn jest…
Norfeldt
  • 8,272
  • 23
  • 96
  • 152
3
votes
0 answers

Edit state variables in React devtools when using a Zustand store

In React devtools you can easily edit and toggle state variables - either stored locally, in Context, or with some fancy add-ons like redux devtools. Is there a way to do that with Zustand store hooks? It seems to me like they're just readonly.
crevulus
  • 1,658
  • 12
  • 42
3
votes
1 answer

Adding persist middleware to zustand store

I want to add a persist middleware to my useGlobalStore. I want to handle there (set and get) data for sessions store. I look through documentation but could not find an answer how to combine together my create and persist functions. Here is my…
Yana Trifonova
  • 586
  • 7
  • 28
3
votes
0 answers

Handling relational data in Zustand

I need some input from people more experienced with Zustand to share their way of managing relational state. Currently we have the following: Let's assume we have the example entities Campaign, Elementss and their Settings. The REST API returning…
3
votes
4 answers

Using a (Zustand) function mock with Jest results in "TypeError: create is not a function"

I'm following the Zustand wiki to implement testing, but the provided solution is not working for a basic test for app rendering. My project is built on top of the Electron React Boilerplate boilerplate project. Here's the full error. Jest is using…
fowl-
  • 41
  • 1
  • 4
3
votes
2 answers

Property 'filter' does not exist on type object

I'm working with zustand and typescript. I got this error on my code Property 'filter' does not exist on type 'object'.ts(2339) I don't know how to fix this problem. I'm creating an object from my useStore library. I tried usin 'type' but it throws…
Karol
  • 166
  • 1
  • 4
  • 15
2
votes
0 answers

React & Zustand & Immer Asynchronous update state

I'm using React with zustand and the immer middleware of zustand. I use a custom class in the zustand store, and with immer I can update the state and the custom class instance in the state with mutable patterns. At most of times, everything works…
2
votes
0 answers

zustand next 13 set initial state on server and get state on client

i have next 13 application and i am using zustand as my state manager currently i have a simple layout that looks like this
2
votes
1 answer

Uncaught TypeError: rawData.some is not a function REACT/ANTDESIGN

I am trying to solve this problem almost for 1 day. I considered every possible solution, have been searching for a long time, but really have no idea what's wrong. I need to make table with ant design and on initial rendering all the users should…
2
votes
1 answer

Error with Zustand and Typescript when using Persist. The Error is: persist.d.ts(95, 210): An argument for 'options' was not provided

I'm trying to use the persist functionality using Zustand following the pattern on the Zustand documentation for Typescript but I get an error when I add the persist method. The error is persist.d.ts(95, 210): An argument for 'options' was not…
1
2
3
15 16