Capxul Docs
HooksAddress book

useCapxulAddressBookEntry

Query hook for one address-book entry of an actor, by entry id — null when no relationship exists.

Reads a single address-book entry for an actor scope. Use it for a contact detail view after listing entries with useCapxulAddressBook.

Import

import { capxulAccountScope, useCapxulAddressBookEntry } from "@capxul/sdk-react";

Usage

"use client";

import { capxulAccountScope, useCapxulAddressBookEntry } from "@capxul/sdk-react";

function ContactCard({ entryId }: { entryId: string }) {
  const entry = useCapxulAddressBookEntry(capxulAccountScope, entryId);

  if (entry.isLoading) return <p>Loading contact…</p>;
  if (entry.error) return <p>{entry.error.message}</p>;
  if (entry.data === null) return <p>No relationship with this contact yet.</p>;

  return (
    <div>
      <h2>{entry.data.label}</h2>
      <p>{entry.data.relationship.join(", ")}</p>
    </div>
  );
}

Parameters

actor

CapxulActorScope | undefined

The actor scope whose address book to read. The query stays disabled while the scope is undefined.

entryId

string | undefined

The entry id, as returned by useCapxulAddressBook or one of the address-book mutations. The query stays disabled while entryId is undefined, so you can pass route params or other query results directly.

options

{ enabled?: boolean } | undefined

Set enabled: false to hold the query even when scope and id are ready.

Return type

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

data is the AddressBookEntry, or null when the actor has no relationship with that counterparty:

Prop

Type

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", "actor", "account", "addressBook", entryId]      // personal scope
["capxul", "actor", "org", orgId, "addressBook", entryId]   // org scope

("pending" fills the actor and/or entryId segment while either is undefined.) Invalidated by any address-book mutation for the same scope that returns this entry, and by payment-requests / inbox mutations that name its id.

Errors

An entryId that is not a valid address-book entry id fails with a CapxulError (invalid input) on error — always pass ids the SDK produced, not hand-built strings.

Client method

This hook wraps client.account.addressBook.get(entryId) for the personal scope, or client.org(orgId).addressBook.get(entryId) for an org scope.

On this page