UNPKG

@towns-protocol/react-sdk

Version:

React Hooks for Towns Protocol SDK

28 lines 1 kB
'use client'; import { useMemo } from 'react'; import { useSyncAgent } from './useSyncAgent'; import { useObservable } from './useObservable'; /** * Hook to get data about a space. * You can use this hook to get space metadata and ids of channels in the space. * @param spaceId - The id of the space to get data about. * @param config - Configuration options for the observable. * @returns The SpaceModel data. * @example * You can use this hook to display the data about a space: * * ```tsx * import { useSpace } from '@towns-protocol/react-sdk' * * const Space = ({ spaceId }: { spaceId: string }) => { * const { data: space } = useSpace(spaceId) * return <div>{space.metadata?.name || 'Unnamed Space'}</div> * } * ``` */ export const useSpace = (spaceId, config) => { const sync = useSyncAgent(); const observable = useMemo(() => sync.spaces.getSpace(spaceId), [sync, spaceId]); return useObservable(observable, config); }; //# sourceMappingURL=useSpace.js.map