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
PlaceSpaceProvider 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
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.
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
The loaded space object.
undefined while loading, null if not found.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’smemberPermissions, 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.
true if the current user can post entities in this space, as the server reports it (see How permissions are calculated).The current user’s raw membership status.
null if they have no membership.Hierarchy
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.Preview of the immediate parent space.
null for root spaces, and when the user can’t see the parent (space.parentSpaceId still names it).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
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.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.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.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.
