# define-zustand

> > Quickly define [zustand](https://github.com/pmndrs/zustand) state. Supports defining computed properties.

Latest version **4.0.2** (published 2026-07-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install define-zustand
pnpm add define-zustand
yarn add define-zustand
bun add define-zustand
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2026-07-16 |
| First published | 2023-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | 1k_npm |

## Links

- npm: https://www.npmjs.com/package/define-zustand
- npm.io page: https://npm.io/package/define-zustand

## Dependencies (3)

- [immer](https://npm.io/package/immer.md) 10.0.2
- [lodash-es](https://npm.io/package/lodash-es.md) 4.17.21
- [@types/react](https://npm.io/package/@types/react.md) 18.3.3

## Recent versions

- 4.0.2 (latest) — 2026-07-16
- 4.0.1 — 2026-03-04
- 4.0.0 — 2026-01-10
- 3.6.0 — 2025-12-27
- 3.5.0 — 2025-09-17
- 3.4.0 — 2025-04-21
- 3.3.0 — 2025-04-16
- 3.2.1 — 2025-02-08
- 3.2.0 — 2025-02-08
- 3.1.1 — 2024-05-27
- 3.1.0 — 2024-01-04
- 3.0.4 — 2023-10-12
- 3.0.3 — 2023-10-12
- 3.0.2 — 2023-10-12
- 3.0.1 — 2023-10-12
- … 6 more at https://npm.io/package/define-zustand/versions

## README

# define-zustand

> Quickly define [zustand](https://github.com/pmndrs/zustand) state. Supports defining computed properties.

## Install

```shell
pnpm i define-zustand
npm i define-zustand
```

## Use

```tsx
import { defineStore, defineContext, defineStateFactory } from 'define-zustand'

/**
 * @return zustand hooks
 */
const useStore = defineStore({
    state: () => ({
        a: 1,
        b: 1
    }),
    getter: {
        count: state => state.a + state.b
    },
    action: () => ({}),
})

// Use defineModelFactory
const stateFactory = defineStateFactory({
    state: () => ({
        a: 1,
        b: 1
    }),
    getter: {
        count: state => state.a + state.b
    },
    action: () => ({}),
})
const useStore = defineStore(stateFactory())
const { Provider, useContext } = defineContext(stateFactory())

function Child() {
    const count = useContext(state => state.count)
    return <div>{count}</div>
}
function ReactComponent() {
    const count = useStore(state => state.count)
    const setState = useStore(state => state.setState)
    const reset = useStore(state => state.reset)

    useEffect(() => {
        return () => {
            reset()
        }
    }, [])

    return (
        <Provider>
            <div>
                <button onClick={() => setState({ a: 2 })}>setA</button>
                <button
                    onClick={() =>
                        setState(state => {
                            state.b += 1
                        })
                    }
                >
                    setB
                </button>
                <div>{count}</div>
            </div>
            <Child />
        </Provider>
    )
}
```

---
_Source: https://npm.io/package/define-zustand · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
