This guide is for users who want to build a custom user interface using the Clerk API. To use a prebuilt UI, use the Account Portal pages or prebuilt components.
This guide will demonstrate how to use the Clerk API to build a custom flow for switching between organizations.
Next.js
JavaScript
The following example:
Uses the useOrganizationList() hook to get memberships, which is a list of the current user's organization memberships. memberships returns data, which is an array of OrganizationMembership objects.
Maps over the data array to display the user's organization memberships in a list.
Provides a button that calls setActive() to set the selected organization as the active organization.
Provides a button to load more organizations if there are more available. The data array is paginated and will only return the first 10 results, so the fetchNext() method is used to load more organizations if they are available.
This example is written for Next.js App Router but can be adapted for any React meta framework, such as Remix.