@towns-protocol/react-sdk
Version:
React Hooks for Towns Protocol SDK
27 lines • 1.11 kB
JavaScript
'use client';
import { Space, assert } from '@towns-protocol/sdk';
import { useMemo } from 'react';
import { useAction } from './internals/useAction';
import { useSyncAgent } from './useSyncAgent';
import { getRoom } from './utils';
/**
* Hook to get the scrollback action for a stream.
*
* Scrollback is the action of getting miniblocks from a stream before a certain point in time.
* Getting miniblocks means that new events that are possibly new messages, reactions and so on are fetched.
*
* @param streamId - The id of the stream to get the scrollback action for.
* @param config - Configuration options for the action.
* @returns The `scrollback` action and its loading state.
*/
export const useScrollback = (streamId, config) => {
const sync = useSyncAgent();
const room = useMemo(() => getRoom(sync, streamId), [sync, streamId]);
assert(!(room instanceof Space), 'cant scrollback spaces');
const { action: scrollback, ...rest } = useAction(room.timeline, 'scrollback', config);
return {
scrollback,
...rest,
};
};
//# sourceMappingURL=useScrollback.js.map