UNPKG

@towns-protocol/react-sdk

Version:

React Hooks for Towns Protocol SDK

19 lines 801 B
import { useMemo } from 'react'; import { Space, assert } from '@towns-protocol/sdk'; import { useSyncAgent } from './useSyncAgent'; import { useObservable } from './useObservable'; import { getRoom } from './utils'; /** * Hook to get the threads from a stream. * * @param streamId - The id of the stream to get the threads from. * @param config - Configuration options for the observable. * @returns The threads of the stream as a map from the message eventId to a thread. */ export const useThreads = (streamId, config) => { const sync = useSyncAgent(); const room = useMemo(() => getRoom(sync, streamId), [streamId, sync]); assert(!(room instanceof Space), 'room cant be a space'); return useObservable(room.timeline.threads, config); }; //# sourceMappingURL=useThreads.js.map