Skip to main content

Command Palette

Search for a command to run...

Growing State Management: A Gentle Introduction to Zustand

Updated
3 min read
Growing State Management: A Gentle Introduction to Zustand

The Garden That Grew Too Wild

Imagine you own a small garden.
Every day you walk through it — watering, trimming, planting new seeds.

At first, it’s peaceful.
But as your garden grows, you start keeping lists — which plant needs sunlight, which one needs trimming, and which one you just planted last week.

Before you know it, your peaceful garden becomes a spreadsheet of chaos.
You’re no longer tending to your plants — you’re managing your management.

If you’ve ever used Redux for state management in React, this might sound familiar.


Enter Zustand: The Self-Tending Garden

“Zustand” means “state” in German.
It’s a lightweight, minimal, and intuitive state management library for React — one that feels like your garden finally learned to take care of itself.

Instead of endless reducers, dispatchers, and action types, you simply create a small store that holds your state and the logic to change it.

Zustand listens quietly in the background — when something changes, it updates only what’s needed, leaving the rest of your app calm and still.


Planting Your First Seeds (Creating the Store)

In this garden, your store is the soil — it holds the roots of every plant.

Here’s your first seed:

import { create } from 'zustand'

const useGardenStore = create((set) => ({
  plants: [],

  addPlant: (name) =>
    set((state) => ({
      plants: [...state.plants, { id: Date.now(), name }]
    })),

  removePlant: (id) =>
    set((state) => ({
      plants: state.plants.filter((p) => p.id !== id)
    })),
}));

Each plant is an object in your garden.
You can add or remove plants — and Zustand will handle the rest, without the ceremony of reducers or dispatchers.


Watching Your Plants Grow (Using the Store in React)

Now let’s step into the garden and see how it grows:

import React, { useState } from 'react';
import useGardenStore from './useGardenStore';

export default function Garden() {
  const { plants, addPlant, removePlant } = useGardenStore();
  const [name, setName] = useState('');

  return (
    <div>
      <input
        value={name}
        onChange={(e) => setName(e.target.value)}
        placeholder="Add a plant..."
      />
      <button onClick={() => addPlant(name)}>Plant</button>

      <ul>
        {plants.map((p) => (
          <li key={p.id}>
            {p.name}
            <button onClick={() => removePlant(p.id)}>Remove</button>
          </li>
        ))}
      </ul>
    </div>
  );
}

Every click, every keystroke — your garden updates instantly.
Zustand automatically re-renders only what changes, keeping your React app fast and lightweight.


Making the Garden Remember (Persistent State)

What if your garden could remember where you left off — even after you close the tab?
With Zustand’s persist middleware, it can:

import { create } from 'zustand'
import { persist } from 'zustand/middleware'

const useGardenStore = create(
  persist(
    (set) => ({
      plants: [],
      addPlant: (name) =>
        set((state) => ({
          plants: [...state.plants, { id: Date.now(), name }]
        })),
    }),
    { name: 'garden-storage' }
  )
);

Now your plants (state) will be stored in localStorage, blooming right where you left them the next time you visit.


Why Developers Love Zustand

Zustand feels alive — a quiet, self-maintaining garden of state.

  • Lightweight: Less than 1 KB gzipped

  • Reactive: Updates only what’s necessary

  • Minimal API: One store, simple syntax

  • Async-ready: Works great with API calls and side effects

It’s state management without the noise — just clean growth.


In the End: Growing Calmly with Zustand

Managing state doesn’t have to feel like pruning a jungle.
With Zustand, it’s like tending a peaceful garden — plant what you need, nurture it as it grows, and trust the system to keep it thriving.

Once you experience the quiet simplicity of Zustand, you’ll wonder how you ever gardened with spreadsheets and dispatchers.