unistash

API reference

createStore, the hook, and helpers.

API reference

createStore(config)

createStore({
  state,      // object
  actions?,   // { [name]: (state, ...args) => Partial<state> }
  computed?,  // { [name]: (state) => value }
}) => useStore

Returns a hook with imperative statics attached.

The hook

useStore()                       // whole snapshot: state + computed + actions
useStore(selector)               // selected slice (Object.is equality)
useStore(selector, equalityFn)   // selected slice (custom equality)

Statics

useStore.getState()              // raw state (no computed/actions)
useStore.setState(partial)       // partial | (state) => partial, shallow-merged
useStore.subscribe(listener)     // (snapshot) => void ; returns unsubscribe

shallow(a, b)

One-level structural equality helper for use as a selector equalityFn.

import { shallow } from "unistash";

On this page