Skip to main content

useOrganizationMemberships

The useOrganizationMemberships hook fetches and provides a list of all organization memberships for the current user.

Return Value

organizationMemberships
OrganizationMembershipWithOrganization[]
List of organization memberships for the current user
loading
boolean
Whether the memberships are loading
error
Error | null
Any error that occurred
refetch
import { useOrganizationMemberships } from "@wacht/tanstack-router";

function OrganizationList() {
  const { organizationMemberships, loading, refetch } = useOrganizationMemberships();

  return (
    <ul>
      {organizationMemberships?.map((membership) => (
        <li key={membership.id}>
          {membership.organization.name}
        </li>
      ))}
    </ul>
  );
}

Data Structures

Examples

List All Organizations

import { useOrganizationMemberships } from "@wacht/tanstack-router";

function OrgList() {
  const { organizationMemberships, loading } = useOrganizationMemberships();

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

  return (
    <ul>
      {organizationMemberships.map((membership) => (
        <li key={membership.id}>
          {membership.organization.name}
        </li>
      ))}
    </ul>
  );
}

Refetch After Update

import { useOrganizationMemberships, useOrganizationList } from "@wacht/tanstack-router";

function OrgManager() {
  const { refetch } = useOrganizationMemberships();
  const { createOrganization } = useOrganizationList();

  const handleCreate = async () => {
    await createOrganization({ name: "New Org" });
    await refetch();
  };

  return <button onClick={handleCreate}>Create Organization</button>;
}