Skip to main content

useOrganizationList()

In B2B applications, a single user profile often belongs to multiple distinct tenants (organizations). The useOrganizationList() hook provides a straightforward, paginated interface to fetch, list, and interact with every organization the current user has access to. It exposes the exact primitives required to build a bespoke <OrganizationSwitcher /> dropdown or an “Accept Invitations” dashboard page.

Import

import { useOrganizationList } from "@wacht/react-router";

Anatomy

loading
boolean
Boolean indicating network boundary readiness.
organizations
Organization[]
List of actual Wacht Organization objects the user is a member of.
error
Error | null
Any error encountered during fetching.
refetch
() => Promise<void>
Manually triggers a re-fetch of the organization list from the server.
Organization Management
Functions
Member & Role Management
Functions
Invitation Management
Functions
Domain Management
Functions
Enterprise Connections (SSO)
Functions
SCIM Directory Sync
Functions

Usage: Building an Invites Page

One of the most powerful uses of this hook is constructing an interface to let users view and accept their pending invitations to join other teams.
import { useOrganizationList } from "@wacht/react-router";

export function UserOrganizations() {
  const { loading, organizations } = useOrganizationList();

  if (loading) return <div>Loading organizations...</div>;

  if (!organizations || organizations.length === 0) {
    return <p>You have no active organizations.</p>;
  }

  return (
    <ul className="divide-y divide-zinc-200">
      {organizations.map((org) => (
        <li key={org.id} className="py-4 flex items-center justify-between">
          <p className="font-medium text-zinc-900">
            {org.name}
          </p>
        </li>
      ))}
    </ul>
  );
}

Interacting With Organizations

The hook provides numerous functions to manipulate organizations if the user holds required permissions, such as:
  • createOrganization(payload)
  • updateOrganization(org, payload)
  • leaveOrganization(org)
  • getOrganizationMembers(org)