Files
snort/packages/system-react/src/useSystemState.tsx
2023-08-17 20:37:10 +01:00

11 lines
324 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(),
);
}