UNPKG

@dark-engine/core

Version:

The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)

16 lines (15 loc) 682 B
import { detectIsFunction, illegal } from '../utils'; import { useLayoutEffect } from '../use-layout-effect'; import { __useSSR as useSSR } from '../internal'; import { useState } from '../use-state'; function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) { const { isSSR } = useSSR(); if (isSSR && !detectIsFunction(getServerSnapshot)) { illegal('getServerSnapshot was not found!'); } const [state, setState] = useState(isSSR ? getServerSnapshot() : getSnapshot()); useLayoutEffect(() => subscribe(() => setState(getSnapshot())), [getSnapshot]); return state; } export { useSyncExternalStore }; //# sourceMappingURL=use-sync-external-store.js.map