Organization switcher
Display a user's organizations and let them switch the active organization.
Clerk · Hook
React hook for accessing a user's organization memberships, invitations, and suggestions. It also supports creating organizations and changing the active organization.
Call this React hook with configuration for the organization data you need. Memberships, invitations, and suggestions are not fetched unless their option is set to true or configured; the returned object also exposes loading state, pagination, organization creation, and active-organization management.
useOrganizationList(options?)| Name | Type | Description |
|---|---|---|
userMemberships | true | { initialPage?: number; pageSize?: number; infinite?: boolean; keepPreviousData?: boolean } | Enables and configures the paginated current-user organization memberships resource; supports true, initialPage, pageSize, infinite, and keepPreviousData. |
userInvitations | true | { initialPage?: number; pageSize?: number; status?: "expired" | "pending" | "revoked" | "accepted"; infinite?: boolean; keepPreviousData?: boolean } | Enables and configures the paginated current-user organization invitations resource; supports invitation status values expired, pending, revoked, or accepted. |
userSuggestions | true | { initialPage?: number; pageSize?: number; infinite?: boolean; keepPreviousData?: boolean } | Enables and configures the paginated current-user organization suggestions resource. |
An object containing isLoaded, configured paginated organization resources such as userMemberships, userInvitations, and userSuggestions, plus methods including createOrganization() and setActive().
true or a detailed configuration object.infinite: true when loading additional pages should extend the existing collection.import { useOrganizationList } from '@clerk/react';
export function OrganizationSwitcher() {
const { isLoaded, setActive, userMemberships } = useOrganizationList({
userMemberships: {
pageSize: 5,
keepPreviousData: true,
},
});
if (!isLoaded) return <p>Loading…</p>;
return (
<ul>
{userMemberships.data?.map((membership) => (
<li key={membership.id}>
<button onClick={() => setActive({ organization: membership.organization.id })}>
{membership.organization.name}
</button>
</li>
))}
</ul>
);
}Loads the current user's organization memberships five at a time and lets each button make its organization active.
Display a user's organizations and let them switch the active organization.
Show pending or filtered organization invitations and let users accept them.
Create a new organization from a custom onboarding flow.
Load organizations incrementally in a paginated or infinite list.
useOrganizationList() provide?It exposes the current user's organization memberships, invitations, and suggestions, along with operations for creating organizations and managing the active organization. These collections require explicit configuration to be populated.
Follow-up: How would you implement an organization switcher? Configure userMemberships, render its data, and call setActive() with the selected organization.
Pass userMemberships: { pageSize: 5, keepPreviousData: true } to request a paginated membership list. The returned paginated resource provides the data and pagination methods for loading more results.
Follow-up: How can the list support infinite scrolling? Set infinite: true, which appends newly fetched results instead of replacing the current list.
The hook returns isLoaded, organization-list resources, createOrganization(), and setActive(). setActive() changes the active organization, while createOrganization() creates one with a supplied name.
Follow-up: How would invitations be handled? Enable userInvitations; each returned invitation can expose an accept() method for accepting it.
useAuthsetActivecreateOrganizationOrganizationMembershipUserOrganizationInvitation<OrganizationSwitcher />