๐ŸŒ
Zustand
zustand.docs.pmnd.rs
Zustand: Introduction
Index of documentation for pmndrs/* libraries
๐ŸŒ
GitHub
github.com โ€บ pmndrs โ€บ zustand
GitHub - pmndrs/zustand: ๐Ÿป Bear necessities for state management in React
Just call set when you're ready, zustand doesn't care if your actions are async or not.
Starred by 57.9K users
Forked by 2K users
Languages ย  TypeScript 97.9% | JavaScript 2.1%
๐ŸŒ
Medium
medium.com โ€บ globant โ€บ react-state-management-b0c81e0cbbf3
React State Management โ€” using Zustand | by Chikku George | Globant | Medium
February 15, 2024 - Zustand store is a hook, which is why useBookStore is the component name. create is the method used to create the store. The store is the sole source of truth that each component shares. The function set is used to modify the state of a variable or object. The function get is used to access the state inside actions. The state object of the library store in the example contains three fields: books, which contains an array of book details such as id, name, and author.
๐ŸŒ
TkDodo
tkdodo.eu โ€บ blog โ€บ working-with-zustand
Working with Zustand
November 20, 2022 - I honestly havenโ€™t needed to combine multiple Zustand stores very often, because most of the state in apps is either server or url state. Iโ€™m far more likely to combine a Zustand store with useQuery or useParams, for example, than I am to combine two separate stores.
๐ŸŒ
Refine
refine.dev โ€บ home โ€บ blog โ€บ integrations โ€บ how to use zustand
How to use Zustand | Refine
August 2, 2024 - It exports a shallow function that we can use to add memoization to our state picks. ... Still using our useCounter as an example, let's say we want to get the counter state from the store.
๐ŸŒ
Reddit
reddit.com โ€บ r/reactnative โ€บ good example projects using zustand + tanstack?
r/reactnative on Reddit: Good example projects using Zustand + Tanstack?
January 30, 2025 -

I'm new to using both Zustand and Tanstack and I'd like to see some good examples of how to integrate both into an application that's more than just a todo app. I'm wondering if anyone can point me to any good examples of what they look like in a larger/more complex application? Thanks

Find elsewhere
๐ŸŒ
Zustand
zustand-demo.pmnd.rs
Zustand
๐Ÿป Bear necessities for state management in React
๐ŸŒ
CodeSandbox
codesandbox.io โ€บ examples โ€บ package โ€บ zustand
zustand examples - CodeSandbox
Use this online zustand playground to view and fork zustand example apps and templates on CodeSandbox.
๐ŸŒ
DEV Community
dev.to โ€บ ricardogesteves โ€บ zustand-when-how-and-why-1kpi
Zustand, When, how and why - DEV Community
September 3, 2024 - Zustand's approach to asynchronous code is straightforward: Direct Integration: Asynchronous functions can be defined directly in the store. No Special Syntax: You don't need to use special action creators or thunks. State Updates: You can update the state within async functions using the set function. Error Handling: Error states can be managed directly within the async functions. Here's an example of how to implement asynchronous code in Zustand:
๐ŸŒ
Medium
medium.com โ€บ @masoudit โ€บ the-complete-guide-to-using-zustand-as-a-state-manager-in-a-react-app-c63c88fe7729
Using Zustand in a React App with Complete Example | by MasoudIt | Medium
January 21, 2024 - To witness the results firsthand, run the project and explore the complete demo showcasing the implementation of Zustand in a sample project. You can find the code in the following repository: React Summit GitHub Repository. In addition to the code above, youโ€™ll discover another example demonstrating the use of Zustand, specifically featuring the Persist API.
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ zustand adoption guide: overview, examples, and alternatives
Zustand adoption guide: Overview, examples, and alternatives - LogRocket Blog
August 27, 2024 - Developer experience (DX) โ€” Zustand offers an amazing DX. Its straightforward API makes it simple to work with, it requires minimal boilerplate code to set up, and itโ€™s intuitive to use for developers who enjoy functional programming. If youโ€™re familiar with React, youโ€™ll enjoy using Zustand as it aligns with Reactโ€™s core principles such as immutable state and unidirectional data flow principles.
๐ŸŒ
Medium
medium.com โ€บ @joris.l โ€บ tutorial-zustand-a-simple-and-powerful-state-management-solution-9ad4d06d5334
[Tutorial] Zustand: A Simple and Powerful State Management Solution | by Joris L. | Medium
June 26, 2023 - In this example, weโ€™ve created a cart including computed values to our store. The computed value is a function that returns the total price of the cart. We use the get function from Zustand to access the items state variable and calculate the totalPrice value.
๐ŸŒ
DEV Community
dev.to โ€บ michaeljota โ€บ zustand-entityadapter-an-entityadapter-example-for-zustand-cd2
Zustand EntityAdapter - An EntityAdapter example for Zustand - DEV Community
March 11, 2024 - Zustand is a state library with a Flux-like API. It gave me vibes of what a Service is for Angular's state management, a simple solution to share state between components. It's like creating a Redux store, with zero boilerplate code, that can be accessed anywhere and it doesn't require to configure a central state manager. The example Zustand has in its introduction page does nothing but show what simple, yet useful it is:
๐ŸŒ
GitHub
github.com โ€บ dhiraj512 โ€บ zustand-example
GitHub - dhiraj512/zustand-example ยท GitHub
With Zustand, you can create, access, and update your application's state in a straightforward manner.
Author ย  dhiraj512
๐ŸŒ
Liveblocks
liveblocks.io โ€บ examples โ€บ browse โ€บ all โ€บ zustand
Zustand examples | Liveblocks
Get inspired with open-source examples powered by Liveblocks and Zustand. Level up your web apps with realtime collaboration. Explore now and start building!
๐ŸŒ
Js
react-tracked.js.org โ€บ person name (zustand)
Tutorial with zustand - Person Name | React Tracked
import * as React from 'react'; import { useState } from 'react'; import create from 'zustand'; type State = { firstName: string; lastName: string; setFirstName: (firstName: string) => void; setLastName: (lastName: string) => void; }; const useStore = create<State>((set) => ({ firstName: 'React', lastName: 'Tracked', setFirstName: (firstName) => set({ firstName }), setLastName: (lastName) => set({ lastName }), })); const EditPerson = () => { const firstName = useStore((state) => state.firstName); const lastName = useStore((state) => state.lastName); const setFirstName = useStore((state) => sta
๐ŸŒ
TkDodo
tkdodo.eu โ€บ blog โ€บ zustand-and-react-context
Zustand and React Context
April 14, 2024 - Not all stores are singletons that ... as well. One example from the past I can think of is a complex, multi-selection group component from our design-system....
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ looking for help on how to use zustand in a large project with complex updates.
r/reactjs on Reddit: Looking for help on how to use Zustand in a large project with complex updates.
March 15, 2024 -

I haven't worked much with state management, at my last job that was already done and the responsibility of a specific team.

I have read the Zustand documentation, but I am confused on other use cases then the most simple use case. Particularly how set() is supposed to work, and it's limits.

  1. Zustand has an Immer middleware, but I have a hard time understanding what it does, and why I should use it over Immer directly. When I do use get() with immer, I keep getting errors from state being Writable and whatever I get() is the actual object, that can't be assigned to a Writable object.

  2. Side Effects. One action might need to do both a get and several sets. Should they be in the same set()? Or chained? I might have to get() an object, update it, then add it's id to changedIds.

I've been trying to find tutorials and examples that show more complex use cases but I've had no luck so far.

Really greateful for any tips, particularly open source projects on GitHub.

Top answer
1 of 3
5
Depends on your use case, but if you truly build a large app with multiple people working on it, I would prepare for some extra effort you have to put into state management, because zustand is very basic. Basically, I see it this way, Zustand in a big project is great, if you need an unopiniated basis to built your own state management, otherwise, you might want to use batteries included frameworks like redux/mobx and so on. Some general things, I can recommend for a big project, with complex updates: Wrap createStore in a custom-function that always applies all the middlewares you need in your project. Noones wants to apply all the middlewares manually everytime they create a store. Use reduxdevtools-middleware for debugging (If you seperate actions from the state, you can build a custom wrapper that always injects a "set"-function with a proper debug info, so not all actions are displayed as "anonymous" in the devtools) Everytime set finishes and updates the state, it triggers all selectors of a particular store. It will not cause a rerender of react for every set, because react batches in intervals, but it might still be costly, if you have alot of expensive selectors. When using immer, my recommendation for "set" is to do as much updates as possible inside the set function, and only use mutliple "sets" if you have async stuff you need to do or when you call another action. Use proxy-memoize for expensive selectors. It is alot less headache than reselect for everyone working on the project Decide early if you want to use one big store, or mutliple independent stores. One big store is easier to use (I still would add a custom abstractions like slices in redux, you can find examples for that in the zustand documentation), but you can run into performance bottlenecks, if not properly maintained. Multiple small store will most likely never run into any performance bottlenecks, but are harder to use when you need to aggregate data from multiple stores. In general, if you are not an experienced developer, I do not recommend using Zustand for a big project, unless your state is very simple. It is for that reason, I don't understand why zustand v5 focuses on an even smaller bundle size instead of adding more documentation and more useful middlewares (like a proper computed values middleware, or a better devtools support without anonymous functions). The API is really great, it just lacks some built-in functionality and documentation at this point.
2 of 3
3
For large project, seperate the state to different stores. And maybe take a look this, No more complex concepts with use-one.js ๐Ÿ‘‡: // stores/count.ts import { create, persistStore, isClient } from 'use-one'; import { produce } from 'immer'; const initialState = { count: 0 }; const [use, store] = create(initialState); isClient && persistStore(store, {key: '@count-info'}); const computed = { get state() { return store.getState(); }, }; const actions = { use, produce(cb: (state: typeof initialState) => void) { store.setState(produce(cb)); }, increment() { this.produce((state) => { state.count++; }); }, decrement() { this.produce((state) => { state.count--; }); }, }; export const countStore = Object.assign(actions, computed, store); // Usage in components export function HelloOne() { countStore.use(); return {JSON.stringify(countStore.state)} } https://www.npmjs.com/package/use-one
๐ŸŒ
YouTube
youtube.com โ€บ watch
Zustand - Complete Tutorial - YouTube
โœจ Cosden Code โ†’ https://cosdencode.com๐Ÿ“ฅ Import React (Newsletter) โ†’ https://cosden.solutions/newsletter?s=ytdJoin The Discord! โ†’ https://discord.cosdensolu...
Published ย  December 18, 2023