Skip to content

Store ​

Overview ​

useStore(name, initialStore) creates or retrieves a named reactive store backed by Vue's reactive(). All stores share a single global Store registry, so calling useStore with the same name from multiple components returns the same reactive object.

Usage ​

javascript
import { useStore } from '@kalisio/kdk/core.client'

const { store, set, get, clear } = useStore('myFeature', { count: 0 })

Parameters ​

ParameterTypeDefaultDescription
namestring—Unique store name within the application. Used as the key in the global registry.
initialStoreObject{}Initial content of the store. Only used on first call for this name; subsequent calls return the existing store.

Exposed ​

NameTypeDescription
StoreObjectThe global store registry (all named stores).
storereactive ObjectThe named store instance.
clear()FunctionRemoves all properties from the store.
set(path, value)FunctionSets a value at the given Lodash path.
get(path, defaultValue?)FunctionGets a value at the given Lodash path. If path is falsy, returns the entire store object.
unset(path)FunctionRemoves a property at the given Lodash path.
has(path)FunctionReturns true if the given Lodash path exists in the store.
forOwn(f)FunctionIterates over all (value, key) pairs in the store and calls f(value, key) for each.

TIP

Because the store is reactive, any component that reads store properties inside a computed or template will automatically update when those properties change.