Skip to content

@acoolhq/react-tiny-store


@acoolhq/react-tiny-store / useStoreActions

Function: useStoreActions()

useStoreActions<T, A>(store, factory, deps): A

Defined in: hooks.ts:92

Build controller actions for a store (side-effects/async allowed).

Type Parameters

T

T

Root state.

A

A

Actions shape returned by the factory.

Parameters

store

Store<T>

The external store.

factory

(api) => A

(api) => actions — may perform side-effects and use other hooks.

deps

any[] = []

Memo deps for the returned actions object.

Returns

A

Actions A (controller actions).

Example

ts
const actions = useStoreActions(store, api => ({
  add(text: string) {
    api.set(p => ({ ...p, todos: [...p.todos, { id: crypto.randomUUID(), text }] }));
  }
}), []);