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

# Add member

> Add a user to a space directly

## Overview

`useAddMember` returns a callable function that adds a user to a space directly. The user becomes an active member at once, with no request or approval step. The signed-in user must be an active moderator or admin of the space.

This is how users get into a private space, which can't be joined. A user with a `pending` or `rejected` membership becomes active; a user who is already an active member is left as they are. A banned user can't be added until they are unbanned (`409 space/member-banned`), nor can a user banned in a parent space (`409 space/banned-in-parent`). A user can't be added when there is a block between them and the adder, in either direction, or when they are suspended (`403 space/user-cannot-be-added`; the response doesn't say which). The added user gets a `space-member-added` notification. See [Add Member](https://docs.sublay.io/v8/api-reference/spaces/membership/add-member.md) for every case and error.

## Usage Example

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

function AddToSpaceButton({ spaceId, userId }: { spaceId: string; userId: string }) {
  const addMember = useAddMember();

  return (
    <button onClick={() => addMember({ spaceId, userId })}>
      Add to space
    </button>
  );
}
```

## Parameters

**spaceId** `string` *required*

UUID of the space.

**userId** `string` *required*

UUID of the user to add.

## Returns

**message** `string`

`"User added to the space."`, or `"User is already a member of this space."` when nothing changed.

**membership** `object`

The user's membership: `id`, `spaceId`, `userId`, `role` (`member` for a user just added; an existing active member keeps their role), `status: "active"`, `joinedAt` and `createdAt`.


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