useActiveWorkspace() is the active-scope wrapper over useWorkspaceList(). It resolves the current active workspace and active workspace membership from the session, then rebinds the workspace-level management methods so they operate on that active workspace automatically.
Usage
The following example shows a basic usage of useActiveWorkspace().
export default function ActiveWorkspaceHeader() { const { activeWorkspace, loading } = useActiveWorkspace(); if (loading) { return <p>Loading workspace…</p>; } return <p>{activeWorkspace?.name ?? 'No active workspace'}</p>;}
Return value
The hook returns the following fields and methods.
›
activeWorkspace: Workspace | null;
Workspace whose membership identifier matches the active sign-in in the session.
›
id?: string | undefined;
Workspace identifier.
›
name?: string | undefined;
Workspace name.
›
image_url?: string | undefined;
Workspace image URL.
›
description?: string | undefined;
Workspace description.
›
member_count?: number | undefined;
Workspace member count.
›
enforce_2fa?: boolean | undefined;
Whether the workspace enforces 2FA.
›
enable_ip_restriction?: boolean | undefined;
Whether the workspace uses IP restrictions.
›
activeMembership: WorkspaceMembership | null;
Current active workspace membership resolved from the session.
›
id?: string | undefined;
Workspace-membership identifier.
›
workspace?: Workspace | undefined;
Workspace attached to the active membership.
›
organization?: Organization | undefined;
Parent organization attached to the active workspace membership.
›
roles?: WorkspaceRole[] | undefined;
Roles attached to the active workspace membership.
This hook is not a separate data source. It wraps useWorkspaceList() and useSession(), then resolves one active workspace and one active membership from the current session.
All of the management methods are rebound to the current active workspace, so callers no longer pass a workspace argument each time.
Invitation helpers need the active workspace together with its parent organization. The hook resolves that by matching the active workspace back into the broader workspaces list from useWorkspaceList().
When there is no active workspace, many methods return empty values or undefined instead of throwing. The docs reflect that behavior because it is part of the current implementation contract.
This is the right hook for workspace-aware pages such as workspace settings, members, roles, and invitations that should always operate on the active workspace only.
When to use it
Examples
Render the active workspace name
export default function ActiveWorkspaceTitle() { const { activeWorkspace, loading } = useActiveWorkspace(); if (loading) { return <p>Loading workspace…</p>; } return <p>{activeWorkspace?.name ?? 'No active workspace'}</p>;}
Load members for the active workspace
export default function ActiveWorkspaceMembers() { const { loading, getMembers } = useActiveWorkspace(); async function loadMembers() { if (loading) { return; } const result = await getMembers({ page: 1, limit: 20, }); console.log(result); } return <button onClick={loadMembers}>Load members</button>;}