Skip to main content

Import

import { useKeystone } from '@keystoneos/react';

Usage

function CustomApiCall() {
  const { baseUrl, tokenManager } = useKeystone();

  const fetchCustomData = async () => {
    const authHeader = await tokenManager.getAuthHeader();
    const res = await fetch(`${baseUrl}/v1/some-endpoint`, {
      headers: { Authorization: authHeader },
    });
    return res.json();
  };

  // ...
}

Parameters

None. Must be used inside a <KeystoneProvider>.

Return Type

interface KeystoneContextValue {
  baseUrl: string;
  tokenManager: SessionTokenManager;
  eventBus: EventBus;
  depositOrchestrator: DepositOrchestrator;
  actionDelegates?: ActionDelegates;
}
PropertyTypeDescription
baseUrlstringThe KeyStone API base URL.
tokenManagerSessionTokenManagerManages session token lifecycle and auth headers.
eventBusEventBusReal-time event subscription system.
depositOrchestratorDepositOrchestratorManages multi-step deposit flows.
actionDelegatesActionDelegates | undefinedAction delegates from the provider.

When to Use

Most integrations should use the higher-level hooks (useSettlement, useDeposit, etc.). Use useKeystone when you need:
  • Direct API calls not covered by existing hooks
  • Custom event subscriptions on the event bus
  • Access to the token manager for auth headers
  • Building your own hooks on top of the core primitives

Example: Custom API Call

function useCustomEndpoint(path: string) {
  const { baseUrl, tokenManager } = useKeystone();
  const [data, setData] = useState(null);

  useEffect(() => {
    (async () => {
      const auth = await tokenManager.getAuthHeader();
      const res = await fetch(`${baseUrl}${path}`, {
        headers: { Authorization: auth },
      });
      setData(await res.json());
    })();
  }, [baseUrl, path, tokenManager]);

  return data;
}

Example: Custom Event Subscription

function useCustomEvents(settlementId: string) {
  const { eventBus } = useKeystone();

  useEffect(() => {
    const unsubscribe = eventBus.subscribe(settlementId, (event) => {
      console.log('Settlement event:', event);
    });
    return unsubscribe;
  }, [settlementId, eventBus]);
}