useStore
useStore(
options?):object
Defined in: packages/@livestore/react/src/useStore.ts:71
Returns the current Store instance from React context, augmented with React-specific methods.
Use this hook when you need direct access to the Store for operations like
store.commit(), store.subscribe(), or accessing store.sessionId.
For reactive queries, prefer useQuery() or useClientDocument() which handle
subscriptions and re-renders automatically.
Parameters
Section titled “Parameters”options?
Section titled “options?”store?
Section titled “store?”Store<Any, { }>
Returns
Section titled “Returns”object
store:
Store<Any, { }> &ReactApi
Examples
Section titled “Examples”const MyComponent = () => { const { store } = useStore()
const handleClick = () => { store.commit(events.todoCreated({ id: nanoid(), text: 'New todo' })) }
return <button onClick={handleClick}>Add Todo</button>}// Access store metadataconst { store } = useStore()console.log('Session ID:', store.sessionId)console.log('Client ID:', store.clientId)// Use with an explicit store instance (bypasses context)const { store } = useStore({ store: myExternalStore })Throws
Section titled “Throws”Error if called outside of <LiveStoreProvider> or before the store is running