Skip to content

usePublicState ​

usePublicState reads public state for the project mounted by SkyStateProvider. See what public state is for. Calls subscribe to a single top-level key and return { value } only. For loading and error status, use useStatus().health.

Must be called inside a component that is a descendant of SkyStateProvider. Throws a SkyStateError if called outside a provider.


Basic Example ​

tsx
import { usePublicState } from '@skystate/react';

export function AnnouncementBanner() {
  const { value: enabled } = usePublicState('bannerEnabled', true);
  const { value: text } = usePublicState('bannerText', 'Welcome!');

  if (!enabled) return null;

  return <div className="banner">{text}</div>;
}

API ​

typescript
function usePublicState<T = unknown>(
  key: string,
): { value: T | null }

function usePublicState<T>(
  key: string,
  fallback: T,
): { value: T | null }

Parameters ​

ParameterDescription
keyTop-level public-state key such as banner, flags, or theme.
fallbackReturned while public state is not ready or when the key is absent. value stays T | null even with a fallback; see Fallback semantics.

Keys are top-level names. They are not nested paths, and '' is not a root-object escape hatch.

Returns ​

CallReturn
usePublicState<T>(key){ value: T | null }.
usePublicState<T>(key, fallback){ value: T | null }.

Public Contract ​

ContractDetail
AuthPublic state is available before login.
Keyed returnKeyed calls return { value } only.
StatusUse useStatus().health for loading and error state.
MetadataUse the console, CLI, or REST API for inspection, audit, or history metadata.