zustand

  • Version 4.5.4
  • Published
  • 325 kB
  • 1 dependency
  • MIT license

Install

npm i zustand
yarn add zustand
pnpm add zustand

Overview

🐻 Bear necessities for state management in React

Index

Variables

variable _default

const _default: Create;
  • Deprecated

    Use import { create } from 'zustand'

variable create

const create: Create;

    variable createStore

    const createStore: CreateStore;

      Functions

      function useStore

      useStore: {
      <S extends WithReact<ReadonlyStoreApi<unknown>>>(api: S): ExtractState<S>;
      <S extends WithReact<ReadonlyStoreApi<unknown>>, U>(
      api: S,
      selector: (state: ExtractState<S>) => U
      ): U;
      <S extends WithReact<ReadonlyStoreApi<unknown>>, U>(
      api: S,
      selector: (state: ExtractState<S>) => U,
      equalityFn: (a: U, b: U) => boolean
      ): U;
      };
      • Deprecated

        The usage with three arguments is deprecated. Use useStoreWithEqualityFn from 'zustand/traditional'. The usage with one or two arguments is not deprecated. https://github.com/pmndrs/zustand/discussions/1937

      Interfaces

      interface StoreApi

      interface StoreApi<T> {}

        property destroy

        destroy: () => void;
        • Deprecated

          Use unsubscribe returned by subscribe

        property getInitialState

        getInitialState: () => T;

          property getState

          getState: () => T;

            property setState

            setState: SetStateInternal<T>;

              property subscribe

              subscribe: (listener: (state: T, prevState: T) => void) => () => void;

                interface StoreMutators

                interface StoreMutators<S, A> {}

                  interface StoreMutators

                  interface StoreMutators<S, A> {}

                    property 'zustand/redux'

                    'zustand/redux': WithRedux<S, A>;

                      interface StoreMutators

                      interface StoreMutators<S, A> {}

                        property 'zustand/devtools'

                        'zustand/devtools': WithDevtools<S>;

                          interface StoreMutators

                          interface StoreMutators<S, A> {}

                            property 'zustand/devtools'

                            'zustand/devtools': WithDevtools<S>;

                              interface StoreMutators

                              interface StoreMutators<S, A> {}

                                property ['zustand/subscribeWithSelector']

                                ['zustand/subscribeWithSelector']: WithSelectorSubscribe<S>;

                                  interface StoreMutators

                                  interface StoreMutators<S, A> {}

                                    property 'zustand/persist'

                                    'zustand/persist': WithPersist<S, A>;

                                      interface StoreMutators

                                      interface StoreMutators<S, A> {}

                                        property ['zustand/immer']

                                        ['zustand/immer']: WithImmer<S>;

                                          Type Aliases

                                          type Destroy

                                          type Destroy = () => void;
                                          • Deprecated

                                            Use StoreApi<T>['destroy'] instead of Destroy.

                                          type EqualityChecker

                                          type EqualityChecker<T> = (state: T, newState: T) => boolean;
                                          • Deprecated

                                            Use (a: T, b: T) => boolean instead of EqualityChecker<T>

                                          type GetState

                                          type GetState<T extends State> = () => T;
                                          • Deprecated

                                            You might be looking for StateCreator, if not then use StoreApi<T>['getState'] instead of GetState<T>.

                                          type Mutate

                                          type Mutate<S, Ms> = number extends Ms['length' & keyof Ms]
                                          ? S
                                          : Ms extends []
                                          ? S
                                          : Ms extends [[infer Mi, infer Ma], ...infer Mrs]
                                          ? Mutate<StoreMutators<S, Ma>[Mi & StoreMutatorIdentifier], Mrs>
                                          : never;

                                            type PartialState

                                            type PartialState<T extends State> = Partial<T> | ((state: T) => Partial<T>);
                                            • Deprecated

                                              Use Partial<T> | ((s: T) => Partial<T>) instead of PartialState<T>

                                            type SetState

                                            type SetState<T extends State> = {
                                            _(
                                            partial:
                                            | T
                                            | Partial<T>
                                            | {
                                            _(state: T): T | Partial<T>;
                                            }['_'],
                                            replace?: boolean | undefined
                                            ): void;
                                            }['_'];
                                            • Deprecated

                                              You might be looking for StateCreator, if not then use StoreApi<T>['setState'] instead of SetState<T>.

                                            type State

                                            type State = unknown;
                                            • Deprecated

                                              Use unknown instead of State

                                            type StateCreator

                                            type StateCreator<
                                            T,
                                            Mis extends [StoreMutatorIdentifier, unknown][] = [],
                                            Mos extends [StoreMutatorIdentifier, unknown][] = [],
                                            U = T
                                            > = ((
                                            setState: Get<Mutate<StoreApi<T>, Mis>, 'setState', never>,
                                            getState: Get<Mutate<StoreApi<T>, Mis>, 'getState', never>,
                                            store: Mutate<StoreApi<T>, Mis>
                                            ) => U) & {
                                            $$storeMutators?: Mos;
                                            };

                                              type StateListener

                                              type StateListener<T> = (state: T, previousState: T) => void;
                                              • Deprecated

                                                Use (state: T, previousState: T) => void instead of StateListener<T>

                                              type StateSelector

                                              type StateSelector<T extends State, U> = (state: T) => U;
                                              • Deprecated

                                                Use (s: T) => U instead of StateSelector<T, U>

                                              type StateSliceListener

                                              type StateSliceListener<T> = (slice: T, previousSlice: T) => void;
                                              • Deprecated

                                                Use (slice: T, previousSlice: T) => void instead of StateSliceListener<T>.

                                              type StoreMutatorIdentifier

                                              type StoreMutatorIdentifier = keyof StoreMutators<unknown, unknown>;

                                                type Subscribe

                                                type Subscribe<T extends State> = {
                                                (listener: (state: T, previousState: T) => void): () => void;
                                                };
                                                • Deprecated

                                                  Use (listener: (state: T) => void) => void instead of Subscribe<T>.

                                                type UseBoundStore

                                                type UseBoundStore<S extends WithReact<ReadonlyStoreApi<unknown>>> = {
                                                (): ExtractState<S>;
                                                <U>(selector: (state: ExtractState<S>) => U): U;
                                                /**
                                                * @deprecated Use `createWithEqualityFn` from 'zustand/traditional'
                                                */
                                                <U>(
                                                selector: (state: ExtractState<S>) => U,
                                                equalityFn: (a: U, b: U) => boolean
                                                ): U;
                                                } & S;

                                                  Package Files (8)

                                                  Dependencies (1)

                                                  Dev Dependencies (0)

                                                  No dev dependencies.

                                                  Peer Dependencies (3)

                                                  Badge

                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/zustand.

                                                  • Markdown
                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/zustand)
                                                  • HTML
                                                    <a href="https://www.jsdocs.io/package/zustand"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>