Zust2help Upd
While Zustand makes updates easy, dealing with nested structures still requires care. If you are not using the direct mutation syntax, you must ensure you are copying nested structures correctly to prevent reference bugs.
Scenario: Updating a User’s Address
const useProfileStore = create((set) => ({
user: {
name: 'Alice',
details: {
age: 25,
city: 'New York'
}
},
// The Modern Way (Direct Mutation via Immer)
updateCity: (newCity) => set((state) => {
state.user.details.city = newCity;
}),
// The Traditional Way (Spreading)
updateCityOldSchool: (newCity) => set((state) => ({
user: {
...state.user,
details: {
...state.user.details,
city: newCity
}
}
}))
}));
Notice how the "Modern Way" is significantly cleaner and less error-prone. zust2help upd
👇 Drop your experience or questions below!
Tag a friend who still goes to the wrong building for forms.
#ZUST #ZUST2Help #CampusLife #StudentSupport #Update While Zustand makes updates easy, dealing with nested
Since "zust2help" sounds like a play on Zustand (the popular React state management library) combined with "help" or an update tool, I have written a blog post positioning zust2help as a conceptual open-source utility library designed to make Zustand migrations and debugging easier.
Here is an interesting, engaging blog post structure for you. Notice how the "Modern Way" is significantly cleaner
One of the reasons Zustand is so popular is that it allows you to mutate state directly. Under the hood, Zustand uses a library called Immer (or similar logic), which creates a draft state. This means you don't need to spread operators (...state) for every update.
The Syntax:
import { create } from 'zustand';
const useBearStore = create((set) => ({
bears: 0,
// Simple update function
increasePopulation: () => set((state) => ({
bears: state.bears + 1
})),
// The "Direct Mutation" approach (Recommended for simplicity)
removeAllBears: () => set((state) => {
state.bears = 0
}),
}));
In the removeAllBears example above, we are assigning 0 to state.bears directly. This feels unnatural if you are used to Redux's immutability principles, but in Zustand, this is valid and encouraged.
Cause: Network instability during download corrupted a file. Solution: Clear the update cache and retry.
sudo rm -rf /var/cache/zust2help/upd/*
zust2help upd --apply --force