import { CursorState } from '@getguru/slate-yjs-core'; import { useSyncExternalStore } from 'use-sync-external-store/shim'; import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'; import { useRemoteCursorStateStore } from './useRemoteCursorStateStore'; export function useRemoteCursorStates< TCursorData extends Record = Record >() { const [subscribe, getSnapshot] = useRemoteCursorStateStore(); return useSyncExternalStore(subscribe, getSnapshot); } export function useRemoteCursorStatesSelector< TCursorData extends Record = Record, TSelection = unknown >( selector: (cursors: Record>) => TSelection, isEqual?: (a: TSelection, b: TSelection) => boolean ): TSelection { const [subscribe, getSnapshot] = useRemoteCursorStateStore(); return useSyncExternalStoreWithSelector( subscribe, getSnapshot, null, selector, isEqual ); }