Skip to main content
The SpaceProvider and useSpace hook are the primary way to work with a single space in your app. The provider fetches and manages the space data; the hook exposes everything to your components.

SpaceProvider

Place SpaceProvider anywhere in your tree where space data is needed. You can identify the space by UUID, shortId, or slug — or skip the fetch entirely by passing a pre-fetched space object directly.

Props

string
UUID of the space to load. Use this, shortId, or slug.
string
Short identifier of the space. Use this, spaceId, or slug.
string
URL slug of the space. Use this, spaceId, or shortId.
SpaceDetailed
A pre-fetched space object. Skips the initial fetch if provided. Useful for SSR or when the space is already loaded in a parent component.
SpaceIncludeParam
Optional. A single value or an array; the only value is "files". Pass it to include avatar and banner file data in the fetched space.
SpaceProvider renders null if none of spaceId, shortId, slug, or space is provided.

useSpace

useSpace must be called inside a descendant of SpaceProvider.

Return Values

Space State

SpaceDetailed | null | undefined
The loaded space object. undefined while loading, null if not found.
boolean
true while the space is being fetched.
SublayError | null
The last failure loading the space or running one of its operations (update, delete, join, leave), with the server’s message and code. A SublayError.

Membership & Permissions

These flags come from the space’s memberPermissions, which the server always returns, for members and non-members alike. After joinSpace or leaveSpace the hook fetches the space again to pick up the new ones (a repeat join succeeds with the existing membership and reloads it the same way; a leave by a user shown as an active member that answers space/membership-required means an earlier leave already went through, and also reloads it), and an update returns them. Until the space has loaded they are all false; the SDK never works them out from the space’s settings.
boolean
true if the current user has an active membership in this space.
boolean
true if the current user is an admin of this space.
boolean
true if the current user is a moderator of this space.
boolean
true if the current user can post entities in this space, as the server reports it (see How permissions are calculated).
boolean
true if the current user can read content in this space.
boolean
true if the current user can perform moderation actions in this space.
"pending" | "active" | "banned" | "rejected" | null
The current user’s raw membership status. null if they have no membership.
boolean
true if the user’s join request is awaiting approval.
boolean
true if the user is banned from this space.

Hierarchy

SpaceBreadcrumbEntry[]
The path from the top-level space down to this space, root first. A space above that the user can’t see (a private space they aren’t an active member of, or a space under one) is exactly { hidden: true }; every other entry has the space’s id, name, slug and so on, with hidden: false. Skip hidden entries, show ”…”, or start after the last hidden one.
SpacePreview | null
Preview of the immediate parent space. null for root spaces, and when the user can’t see the parent (space.parentSpaceId still names it).
SpacePreview[]
Previews of direct child spaces (up to 10 returned by the API): the direct sub-spaces the viewer can see that are public or that the viewer is an active member of.

Operations

() => Promise<void>
Join the current space. If the space requires approval, the membership enters pending status. The space is then fetched again, so memberPermissions become the server’s answer for the new membership.
() => Promise<void>
Leave the current space. The space is then fetched again, so memberPermissions become the server’s answer for the user as a non-member. A space the user can no longer see once they have left (a private space) becomes null.
(changes: Omit<UpdateSpaceProps, "spaceId">) => Promise<SpaceWithPermissions | undefined>
Update space settings. Only available to admins. Takes the changes alone, e.g. updateSpace({ name }): the fields of useUpdateSpace except spaceId, including avatarFile, bannerFile and removeFileIds. Resolves with the updated space and the user’s memberPermissions after the update; the local space takes both and keeps its parentSpace and childSpaces.
() => Promise<void>
Delete the space and all associated data. Only the space’s owner can delete it: its userId, which is the creator of a top-level space and the root space’s creator for a sub-space.
React.Dispatch
Directly set the space state. Useful for optimistic local updates.

Example: Space Page with Membership Button

See Also