What does HackerNews think of zustand?

🐻 Bear necessities for state management in React

Language: TypeScript

> State in Svelte goes in stores. State in react seems to go in one of eighteen different mechanisms, which all begin with a 45 minute video of the author’s opinions about the true nature of reactive programming, when all I want to do is store a string.

So... useState? :)

Of course then I got to thinking about how I'd answer the question "How can I put make that useState value accessible at different points in the component tree?" and the answer was "Make a new context with createContext and wrap the context provider in a component which provides the state and write a hook to easily consume the context within a child component" and, yeah, that's not exactly a frictionless dev experience.

FWIW for simple state management in React I've heard lots of good things about zustand: https://github.com/pmndrs/zustand

I work with React (NextJS) and from working on things in Vue, and Nuxt - the one thing I absolutely hate about React is state management. If you have never used Pinia[0] (Vuex) with Vue, it's just so, so, so much easier.

I'm using Zustand[1] with React as it is as similar as I can find to Pinia, but the whole hook system is just painful to work with... OK rant over.

I haven't built anything substantial with Svelte, but it's definitely on the radar, and I like how similar it is to Vue single file components (SFC). Hoping state management will be as nice to work with as Pinia is with Vue.

[0] https://pinia.vuejs.org/

[1] https://github.com/pmndrs/zustand

Zustand is great: https://github.com/pmndrs/zustand

It gets out of the way in terms of boilerplate, has a good solution for avoiding unnecessary re-renders, has tooling for deep state updates without messy syntax (immer) and strikes an overall good balance between powerful and easy to use. Cons might be that it is a bit more obscure so people might have to learn it. Also the learning curve is a bit steep. YMMV

Just fyi, there is no need to use Redux just because you're using React.

If it's a pretty simple case, you can use the built in `useReducer`[0]. Or if you want something that'll scale but that's much more lightweight than Redux, I'd recommend Zustand[1].

[0] https://reactjs.org/docs/hooks-reference.html#usereducer [1] https://github.com/pmndrs/zustand

I like it a lot. If you're a 'react' 'developer', also have a look at Zustand. https://github.com/pmndrs/zustand
A provider-less context-less alternative: https://github.com/pmndrs/zustand
If you want a simple and elegant state management module then check out Zustand. I have been using this for a year or a bit more and am absolutely happy with it.

https://github.com/pmndrs/zustand