Capxul Docs
HooksOrganizations

useCapxulOrg

Query hook for a single organization you belong to, resolved by org id — null when you are not a member.

Reads one organization from your org list, by id. Returns null when the org is not in your list — an org you do not belong to is indistinguishable from one that does not exist. For the full list use useCapxulOrgs.

Import

import { useCapxulOrg } from "@capxul/sdk-react";

Usage

"use client";

import type { OrgId } from "@capxul/sdk";
import { useCapxulOrg } from "@capxul/sdk-react";

function OrgHeader({ orgId }: { orgId: OrgId }) {
  const org = useCapxulOrg(orgId);

  if (org.isLoading) return <p>Loading organization…</p>;
  if (org.error) return <p>{org.error.message}</p>;
  if (org.data === null) return <p>Organization not found.</p>;

  return (
    <header>
      <h2>{org.data.name}</h2>
      <p>
        @{org.data.handle} · your role: {org.data.role}
      </p>
    </header>
  );
}

Parameters

orgId

OrgId | undefined

The organization to read. The query stays disabled while orgId is undefined, so you can pass a not-yet-resolved value (a route param, the result of another query) directly — no manual gating needed.

options

UseCapxulOrgOptions | undefined

Prop

Type

Return type

import { type UseCapxulOrgReturn } from "@capxul/sdk-react";
// UseQueryResult<OrgView | null, CapxulError>

data is the OrgView for the requested org — see useCapxulOrgs for the field list — or null when the org is not in your list.

The hook returns TanStack Query's UseQueryResult. The most-used fields:

FieldDescription
dataThe query data (typed per hook, shown above). undefined until the first success.
errorA CapxulError when the last fetch failed, otherwise null.
status'pending' | 'error' | 'success'.
isLoadingtrue during the first fetch (no data yet).
isFetchingtrue whenever a fetch is in flight, including background refetches.
refetchManually refetch the query.

Capxul query hooks stay pending until the provider finishes bootstrapping — you do not need to gate them on useCapxul() yourself. The full field list is in the TanStack Query useQuery reference; see also the TanStack Query integration guide.

Query key

["capxul", "org", orgId] — the root of the org-scoped key hierarchy (members, roles, treasury, … nest under it). Invalidated on success by useCapxulOrgDeployRoles for the same org.

Client method

This hook wraps client.orgs() and narrows the result to the requested orgId — the core SDK has no single-org read on its surface.

On this page