Skip to main content

API

Complete reference for the currently available public API.

create(initialValue)

Creates a new store with an initial value.

import { create } from "@bentoo/state-man";

const useCounter = create(0);
const useUser = create({ name: "Ada", age: 28 });

Returns a React hook that can be used inside components.

store() – React Hook

The store created by create() is a hook. Use it inside a component:

const { state, setState } = useCounter();

This hook returns:

  • state: the current value of the store
  • setState: a function to update the state

setState(nextValue | updaterFn)

Updates the store's state.

Direct value

setState(42);
setState({ name: "Alan" });

Updater function

Safer for asynchronous cases or when relying on the previous value:

setState(prev => prev + 1);
setState(prev => ({ ...prev, active: true }));

Full API (hook return)

PropertyTypeDescription
stateTCurrent value of the store
setState(next: T) => void or (fn: (prev: T) => T) => voidUpdates the state

Notes

  • The store only triggers a re-render if the value actually changes.
  • Updates are local and isolated: only the components that consume the store are affected.
  • No Context, Provider, or external configuration needed.

📚 See also: Comparisons