State Management · Senior · Question 17 of 75
How do you persist only some fields of a Zustand store and handle schema changes?
- ✓Correct answer: Use
partializeto pick fields andversion+migratefor old data - 2Create a separate store per field
- 3Persistence always saves the whole store and can't migrate
Explanation
persist(fn, { name, partialize: (s) => ({ cart: s.cart }), version: 2, migrate: (old, v) => ... }). Without migrations, a renamed field leaves broken data in users' storage.