Skip to main content

Overview

useSpace returns the current space state and all operations from the nearest SpaceProvider. It is the primary way to interact with a space in your component tree. The permission flags (isMember, canPost, canRead, …) come from the space’s memberPermissions, which the server always returns. 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. They are all false until the space has loaded.
This hook must be used inside a SpaceProvider.

Usage Example

Returns

SpaceDetailed | null | undefined
The loaded space. undefined while loading, null if not found.
boolean
true while fetching the space.
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.
boolean
true if the current user has an active membership.
boolean
true if the current user is a space admin.
boolean
true if the current user is a space moderator.
boolean
true if the current user can post entities in this space.
boolean
true if the current user can read content in this space.
boolean
true if the current user can perform moderation actions.
"pending" | "active" | "banned" | "rejected" | null
Raw membership status. null if the user has no membership.
boolean
true if the user’s join request is awaiting approval.
boolean
true if the user is banned from this space.
SpaceBreadcrumbEntry[]
The path from the top-level space down to this space, root first. A space above that the user can’t see is { hidden: true }; see useFetchSpaceBreadcrumb.
SpacePreview | null
Preview of the parent space. null for root spaces, and when the user can’t see the parent.
ChildSpacePreview[]
Previews of direct child spaces (up to 10): the direct sub-spaces the viewer can see that are public or that the viewer is an active member of. Each is a SpacePreview plus its readingPermission.
() => Promise<void>
Join the space. Creates a pending membership when approval is required. The space is then fetched again, so its memberPermissions become the server’s answer for the new membership.
() => Promise<void>
Leave the space. The space is then fetched again, so its 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 (admin only). 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. 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 update the space state for optimistic UI updates.
For integration guidance, see SpaceProvider & useSpace.