Skip to main content

Claude/ChatGPT Prompt to Set Up Zustand State Instead of Redux

Set up a typed Zustand store with slices, devtools and persist middleware, and shallow selectors for a React/Next.js app.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt directs the AI to set up Zustand state management for an app you name, returning strict TypeScript rather than pseudocode. You provide the [app], the store [slices], and the [persisted] slices. It produces a single store composed from per-slice creators, devtools middleware named per slice, persist middleware applied only to the persisted slices with a partialize selector, shallow-compare selector hooks, strict types with no any, and an example component reading and updating via narrow selectors.

The structure works because Zustand's flexibility makes it easy to misuse — especially over-persisting state. By splitting the store into [slices] and applying persist only to [persisted] with partialize, the prompt keeps transient data out of storage. [slices] defines the store's shape and where actions live, [persisted] controls exactly what survives a reload, and the strict-TypeScript requirement ensures action signatures are inferred and the store type is exported for reuse.

When to use it

  • You're choosing Zustand over Redux and want a clean, typed baseline.
  • You need a store split into slices, each with its own state and actions.
  • You want devtools wired for the Redux DevTools extension, named per slice.
  • You need persistence on only some slices, never live data.
  • You're fighting unnecessary re-renders and want shallow-compare selectors.
  • You want strict TypeScript with no any and an exported store type.

Example output

You get the store file(s) and an example component in separate code blocks: a single store composed from per-slice creators for each entry in [slices], each with its own actions and state; devtools middleware wired for the Redux DevTools extension and named per slice; persist middleware applied only to [persisted] with a partialize selector so transient state is never saved; selector hooks using shallow compare to prevent unnecessary re-renders; strict TypeScript with no any, inferred action signatures, and an exported store type; and an example component that reads and updates the store via narrow selectors.

Pro tips

  • Be deliberate about [persisted] — persist only auth and a couple of UI preferences, never live data, or you'll ship stale state to users after a reload.
  • Define [slices] to match real domains in [app]; clean slice boundaries keep actions colocated and make the store easier to reason about.
  • Use the shallow-compare selector hooks the prompt generates, and read narrow slices in components, to avoid re-rendering on unrelated state changes.
  • Keep the partialize selector tight so transient fields never sneak into storage; this is the most common persistence mistake.
  • Confirm the exported store type is actually imported where you use the store, so you keep end-to-end type safety rather than re-declaring shapes.
  • Ask a follow-up to add a rehydration check if [persisted] includes auth, so you handle the brief moment before persisted state loads.

Frequently Asked Questions

Why use Zustand instead of Redux here?
Zustand offers a much better boilerplate-to-value ratio for most client-side state, with per-slice creators and middleware rather than reducers, actions, and dispatchers. This prompt leans into that by producing a typed sliced store, devtools, and persistence with far less ceremony than an equivalent Redux setup.
Which slices get persisted across reloads?
Only the slices you list in `[persisted]`, applied via persist middleware with a partialize selector. The guidance is to persist auth and a couple of UI preferences but never live data, because over-persisting ships stale state to users when they reload the app.
Does it prevent unnecessary re-renders?
Yes. Deliverable 4 generates selector hooks using shallow compare, and the example component reads narrow selectors. Reading only the specific slice a component needs stops it from re-rendering when unrelated parts of the store change.
Is the output strictly typed?
Yes. The prompt requires strict TypeScript with no `any`, inferred action signatures, and an exported store type. Import that exported type wherever you use the store so you keep end-to-end type safety instead of re-declaring state shapes by hand.
Does it wire up the Redux DevTools extension?
Yes, deliverable 2 adds devtools middleware wired for the Redux DevTools extension and named per slice. Naming actions per slice makes the time-travel and action log readable, which is one of the main debugging advantages you keep from the Redux ecosystem.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in React & Next.js Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support