useStoreState
functionsignature
useStoreState(storeId): { loading: boolean; refresh: () => void; state: unknown; version: number }Lazily fetches a store's full state and keeps it up-to-date via patches.
Parameters
| Name | Type | Description |
|---|---|---|
storeId | null | string | The store ID to track state for, or null to disable. |
Returns
{ loading: boolean; refresh: () => void; state: unknown; version: number }, An object with state, version, loading, and refresh.
Example
example
import { useStoreState } from "@yoltra/devtools-ui";
function StateInspector({ storeId }: { storeId: string }) {
const { state, version, loading, refresh } = useStoreState(storeId);
if (loading) return <p>Loading...</p>;
return (
<div>
<p>Version: {version}</p>
<pre>{JSON.stringify(state, null, 2)}</pre>
<button onClick={refresh}>Refresh</button>
</div>
);
}