Hook to get the spaces of the current user.

Imports

import { useUserSpaces } from '@river-build/react-sdk'

Examples

You can combine this hook with the useSpace hook to get all spaces of the current user and render them:

import { useUserSpaces, useSpace } from '@river-build/react-sdk'

const AllSpaces = () => {
    const { spaceIds } = useUserSpaces()
    return <>{spaceIds.map((spaceId) => <Space key={spaceId} spaceId={spaceId} />)}</>
}

const Space = ({ spaceId }: { spaceId: string }) => {
    const { data: space } = useSpace(spaceId)
    return <div>{space.metadata?.name || 'Unnamed Space'}</div>
}

Definition

function useUserSpaces(
  config?: ObservableConfig.FromObservable<Spaces>,
): {
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
} | {
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
} | {
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
}

Source: useUserSpaces

Parameters

config

  • Type: ObservableConfig.FromObservable<Spaces>
  • Optional

Configuration options for the observable.

Return Type

The list of all space ids of the current user.

{
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
} | {
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
} | {
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
    spaceIds: string[];
}