Skip to content

@acoolhq/react-tiny-store


@acoolhq/react-tiny-store / bindStoreActions

Function: bindStoreActions() ​

bindStoreActions<T, A>(store, factory): (deps) => A

Defined in: hooks.ts:129

Bind a controller factory to a store and get a hook that returns actions.

Type Parameters ​

T ​

T

Root state.

A ​

A

Actions shape.

Parameters ​

store ​

Store<T>

The external store.

factory ​

(api) => A

(api) => actions (controller actions).

Returns ​

(deps?) => A

(deps): A

Parameters ​

deps ​

any[] = []

Returns ​

A

Example ​

ts
const useTodos = bindStoreActions(store, api => ({
  clear() { api.set(p => ({ ...p, todos: [] })); }
}));

function Toolbar() {
  const { clear } = useTodos();
  return <button onClick={clear}>Clear</button>;
}