Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 1.52 KB

File metadata and controls

29 lines (20 loc) · 1.52 KB

🧐 2. Critique and Comparison with Zustand

Pros of Kosha's SliceCreator<TStore, TSlice> approach

Aspect Kosha
State access in slice Full access to the entire store via TStore
Type-safe set and get Can update any part of the global state if needed
Composable & modular Clear separation between slices while maintaining global awareness
Predictable typing Accurate autocompletion and type inference

⚠️ Zustand’s Slice Pattern

In Zustand:

type Store = UserSlice & ThemeSlice;
const createUserSlice: StateCreator<Store, [], [], UserSlice> = (set, get) => ({ ... })

While Zustand gives get: () => Store and set: (partial | fn), the typing of individual slice creators like createUserSlice forces you to narrow to UserSlice only when accessing fields. This means:

  • ✅ You're safe from accidentally touching unrelated state.
  • ❌ You cannot access sibling slices easily inside the slice unless you explicitly cast get().

Verdict: Kosha’s SliceCreator offers more ergonomic flexibility at the cost of slightly looser constraints. Zustand enforces slice-local purity, but makes cross-slice communication more verbose or error-prone.