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
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.Raw membership status.
null if the user has no membership.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.Preview of the parent space.
null for root spaces, and when the user can’t see the parent.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.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.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.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.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.
