werkbank
    Preparing search index...

    Function atom

    • Creates an atom definition.

      Type Parameters

      • S

        The state type.

      • R extends ReducerMap<S>

        The reducer map type.

      Parameters

      • config: AtomConfig<S, R>

        The atom configuration (initialState, reducers).

      Returns Atom<S, R>

      An atom definition object.

      An atom is a unit of state with an initial value and a set of reducers. It does not hold state itself but defines how state is managed.

      const counterAtom = atom({
      initialState: 0,
      reducers: {
      increment: (state) => state + 1,
      decrement: (state) => state - 1
      }
      });