> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch my spaces

> Fetch, search and sort the spaces the current user is a member of

## Overview

`useFetchMySpaces` returns a callable function that fetches the spaces where the authenticated user has a membership (active by default). The response includes membership metadata alongside each space. Every space the user is an active member of is listed, whatever its visibility, so this is the hook for a "my spaces" screen (a `pending`, `banned` or `rejected` membership of a space the user can't see is left out); [`useFetchManySpaces`](https://docs.sublay.io/v8/hooks/spaces/use-fetch-many-spaces) lists public spaces only. It can search within the user's spaces and sort them.

## Usage Example

```tsx theme={null}
import { useFetchMySpaces } from "@sublay/react-js";

function MySpaces() {
  const fetchMySpaces = useFetchMySpaces();

  const loadSpaces = async () => {
    const result = await fetchMySpaces({ page: 1, limit: 20 });
    // Search within them, A–Z: fetchMySpaces({ query: "design", sortBy: "alphabetical" })
    // Top-level spaces only: fetchMySpaces({ parentSpaceId: "none" })
    // result.data: MySpaceItem[]
    result.data.forEach(({ space, membership }) => {
      console.log(space.name, membership.role, membership.status);
    });
  };
}
```

## Parameters

**status** `string`

Membership status to list: `"active"` (default), `"pending"`, or `"banned"`. Use `"pending"` to show join requests still awaiting approval.

**page** `number`

Page number. Defaults to `1`.

**limit** `number`

Number of results per page.

**role** `SpaceMemberRole | SpaceMemberRole[]`

Only memberships with this role: `"admin"`, `"moderator"` or `"member"`, or an array of them.

**all** `boolean`

`true` returns every matching membership without pagination; the response then has no `pagination`.

**query** `string | null`

Free-text search term, matched as a case-insensitive substring. A blank value is left out of the request, and `searchFields` with it.

**searchFields** `"slug" | "name" | "description" | null`

The one field `query` is matched against. Leave it out to match the slug, the name or the description.

**sortBy** `string`

Sort order: `"joinedAt"` (when the user joined), `"createdAt"` (when the space was created), `"alphabetical"` (by name) or `"members"` (by active member count). Defaults to `"joinedAt"`.

**sortDir** `string`

Direction, `"asc"` or `"desc"`, for any `sortBy`. Left out: A–Z for `"alphabetical"`, otherwise newest / most first.

**parentSpaceId** `string | "none" | "any" | null`

Narrows the list by where each space sits in the tree. `"none"`: the user's memberships in top-level spaces only. A space id: their memberships in that space's direct sub-spaces. `"any"`, left out or `null`: memberships at every level (the default). `null` is left out of the request, never sent as `"none"`.

A membership in a sub-space whose parent the user isn't a member of is not top-level, so `"none"` leaves it out.

**include** `SpaceIncludeParam`

Optional. A single value or an array; the only value is `"files"`. Pass it to populate avatar and banner file objects on each space.

## Returns

**data** `MySpaceItem[]`

Each item contains a `space` ([Space](https://docs.sublay.io/v8/data-models/space.md)) and a `membership` object with `membershipId`, `role`, `status`, and `joinedAt`.

**pagination** `object`

Standard pagination metadata.

See also: [Fetch My Spaces](https://docs.sublay.io/v8/api-reference/spaces/fetch-my-spaces.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.