1
0
forked from Kieran/snort
snort/packages/system-react/src/useSystemState.tsx

11 lines
323 B
TypeScript

import { useSyncExternalStore } from "react";
import { SystemSnapshot } from "@snort/system";
import { ExternalStore } from "@snort/shared";
export function useSystemState(system: ExternalStore<SystemSnapshot>) {
return useSyncExternalStore<SystemSnapshot>(
cb => system.hook(cb),
() => system.snapshot()
);
}