> ## 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.

# Use space list

> Paginated, filterable list of spaces backed by Redux state

## Overview

`useSpaceList` provides a stateful, paginated list of spaces with support for filtering, sorting, search, and creation. Each list is identified by a `listId` and maintains independent Redux state, allowing multiple lists on the same page.

For full integration guidance, see [Space Lists](https://docs.sublay.io/v7/sdk/spaces/space-lists.md).

## Usage Example

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

function SpaceDirectory() {
  const { spaces, loading, hasMore, fetchSpaces, loadMore } = useSpaceList({ listId: "directory" });

  useEffect(() => {
    fetchSpaces({ sortBy: "newest" });
  }, []);

  return (
    <div>
      {spaces.map((space) => <div key={space.id}>{space.name}</div>)}
      {hasMore && <button onClick={loadMore} disabled={loading}>Load more</button>}
    </div>
  );
}
```

## Parameters

**listId** `string` *required*

Unique identifier for this list's Redux state slice. Use distinct IDs for independent lists.

## Returns

**spaces** `Space[]`

Currently loaded spaces.

**loading** `boolean`

`true` while fetching.

**hasMore** `boolean`

`true` if more pages are available.

**fetchSpaces** `function`

Trigger a new fetch. Resets to page 1. Accepts filter and config parameters.

```ts theme={null}
fetchSpaces(
  filters: {
    sortBy?: "newest" | "members" | "alphabetical";
    searchSlug?: string | null;
    searchName?: string | null;
    searchDescription?: string | null;
    searchAny?: string | null;
    memberOf?: boolean;
    parentSpaceId?: string | null;
  },
  config?: { limit?: number },
  options?: { fetchImmediately?: boolean; resetUnspecified?: boolean; clearImmediately?: boolean }
) => void
```

**loadMore** `() =\> void`

Fetch the next page and append results.

**createSpace** `function`

Create a new space and insert it into the list.

```ts theme={null}
createSpace(props: {
  name: string;
  slug?: string | null;
  description?: string | null;
  readingPermission?: "anyone" | "members";
  postingPermission?: "anyone" | "members" | "admins";
  visibility?: "public" | "unlisted" | "private";
  requireJoinApproval?: boolean;
  metadata?: Record<string, any>;
  parentSpaceId?: string | null;
  insertPosition?: "first" | "last";
}) => Promise<Space | undefined>
```

> [!NOTE]
>
> Space avatars and banners are uploaded as files, not URLs, so they can't be
> set through this hook. Use [useCreateSpace](https://docs.sublay.io/v7/hooks/spaces/use-create-space.md)
> or [useUpdateSpace](https://docs.sublay.io/v7/hooks/spaces/use-update-space.md), which send the image as
> `multipart/form-data`.

**deleteSpace** `function`

Delete a space and remove it from the list.

```ts theme={null}
deleteSpace(props: { spaceId: string }) => Promise<void>
```

**sortBy** `string | null`

Current sort setting from Redux state.

**searchSlug** `string | null`

Current slug search query from Redux state.

**searchName** `string | null`

Current name search query from Redux state.

**searchDescription** `string | null`

Current description search query from Redux state.

**searchAny** `string | null`

Current general search query from Redux state.

**memberOf** `boolean`

Current membership filter from Redux state.

**parentSpaceId** `string | null`

Current parent space filter from Redux state.


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