useStore()
function useStore<S extends StoreGeneric>(
useStoreDefinition: (nekuta?: Nekuta) => S
): S;
The hook for functional components. Takes a store definition (what defineStore() returned) and returns the live store, subscribed so the calling component re-renders when it changes.
import { useStore } from '@nekuta/core';
import { useCounterStore } from './stores/counterStore';
function Counter() {
const counter = useStore(useCounterStore);
return <p>{counter.count}</p>;
}
Internally, useStore():
- Resolves the active
Nekutainstance viauseNekuta()(Context, or the module-level singleton fallback). - Calls
useStoreDefinition(nekuta)to get the store. - Returns a tracked proxy over it, re-rendering the component only when a property it actually reads changes — see Reactivity Model for how.
Must be called inside a component wrapped in <NekutaStore> (or with an active instance set via setActiveNekuta()) — otherwise it throws.
useNekuta()
function useNekuta(): Nekuta;
The lower-level hook useStore() itself uses to resolve the active instance: a <NekutaStore> above it in the tree first, falling back to the module-level singleton. You generally won't call this directly unless you're building your own store-consuming hook.