Skip to content

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.

Store<Any, { }>

object

store: Store<Any, { }> & ReactApi

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 metadata
const { 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 })

Error if called outside of <LiveStoreProvider> or before the store is running