Skip to main content

Overview

useFetchMutualSpaces returns a callable function that fetches the spaces both the authenticated user and another user are active members of — their spaces in common. The response is a paginated list of Space objects.

Usage Example

import { useFetchMutualSpaces } from "@sublay/react-js";

function MutualSpaces({ otherUserId }: { otherUserId: string }) {
  const fetchMutualSpaces = useFetchMutualSpaces();

  const loadMutual = async () => {
    const result = await fetchMutualSpaces({ userId: otherUserId, page: 1, limit: 20 });
    // result.data: Space[]
    result.data.forEach((space) => {
      console.log(space.name, space.membersCount);
    });
  };
}

Parameters

userId
string
required
The other user’s ID. Mutual spaces are computed between this user and the authenticated user.
page
number
Page number. Defaults to 1.
limit
number
Number of results per page. Max 100.
include
string | string[]
Optional includes. Pass "files" to populate avatar and banner file objects on each space.

Returns

data
Space[]
The spaces both users share (Space). Computed fields such as membersCount and isMember reflect the authenticated user.
pagination
object
Standard pagination metadata.