Runtime SDKsReact

React API Reference

Complete reference for hooks, provider props, return values, and helpers in @theruntimehq/react

React API Reference

The @theruntimehq/react package exports the following provider, hooks, helper functions, and TypeScript types.

<RuntimeHQProvider>

The root provider component that manages background state synchronization for your application. It maintains an active polling lifecycle with the RuntimeHQ edge network and shares the runtime state with all descendant components via React Context.

Props

PropTypeRequiredDefaultDescription
runtimeKeystringYes—The Runtime Key (rt_prod_... or rt_test_...) for your application. Safe for client-side and browser usage.
intervalSecondsnumberNo60Background polling interval in seconds.

Usage

import { RuntimeHQProvider } from "@theruntimehq/react";

export default function Root() {
  return (
    <RuntimeHQProvider 
      runtimeKey="rt_prod_your_key_here" 
      intervalSeconds={60}
    >
      <App />
    </RuntimeHQProvider>
  );
}

Hooks

useRuntimeHQ

Accesses the global application-level runtime status from the nearest <RuntimeHQProvider>.

import { useRuntimeHQ, isOperational } from "@theruntimehq/react";

function StatusBanner() {
  const { runtime, loading, error } = useRuntimeHQ();

  if (!runtime || isOperational(runtime)) return null;

  return (
    <div className={`banner banner-${runtime.state.toLowerCase()}`}>
      ⚠️ {runtime.message}
    </div>
  );
}

Return Value (RuntimeHQContextValue)

interface RuntimeHQContextValue {
  runtime: RuntimeResponse | null;
  loading: boolean;
  error: Error | null;
  hasCapability: (name: string) => boolean;
  getCapabilityState: (name: string) => CapabilityState | undefined;
}
PropertyTypeDescription
runtimeRuntimeResponse | nullThe full runtime response object containing current application state, message, and capabilities. null before initial fetch completes.
loadingbooleantrue during the initial fetch; false once resolved.
errorError | nullError object if initialization or the initial fetch fails, otherwise null.
hasCapability(name: string) => booleanChecks whether a capability is registered on this application.
getCapabilityState(name: string) => CapabilityState | undefinedReturns the raw CapabilityState object for a capability by name.

useCapability

The recommended, idiomatic hook to monitor feature health, gate workflows, and implement adaptive client behaviors.

import { useCapability } from "@theruntimehq/react";

function SearchComponent() {
  const { isOutage, isDegraded, message } = useCapability("search");

  // Dynamically back off request frequency when search capability is degraded
  const debounceDelayMs = isDegraded ? 1200 : 300;

  return (
    <div className="search-container">
      <input 
        type="search" 
        placeholder="Search products..." 
        disabled={isOutage}
        onChange={debounce(handleSearch, debounceDelayMs)}
      />
      {(isOutage || isDegraded) && message && (
        <p className="helper-text">{message}</p>
      )}
    </div>
  );
}

Parameters

ParameterTypeRequiredDescription
namestringYesThe unique capability identifier configured in RuntimeHQ (e.g., "search", "payments").

Return Value (UseCapabilityResult)

interface UseCapabilityResult {
  capability: CapabilityState | undefined;
  state: RuntimeState;
  message: string;
  isOperational: boolean;
  isDegraded: boolean;
  isOutage: boolean;
  isMaintenance: boolean;
  exists: boolean;
  loading: boolean;
  error: Error | null;
}
PropertyTypeDefault (Fail-Open)Description
isOperationalbooleantruetrue when capability is OPERATIONAL or during initial load / network errors.
isDegradedbooleanfalsetrue when capability state is DEGRADED.
isOutagebooleanfalsetrue when capability state is OUTAGE.
isMaintenancebooleanfalsetrue when capability state is MAINTENANCE.
stateRuntimeState"OPERATIONAL"The resolved runtime state string ("OPERATIONAL", "DEGRADED", "OUTAGE", or "MAINTENANCE").
messagestring""User-facing status or degradation message from RuntimeHQ.
existsbooleanfalsetrue if the capability is registered in configuration.
capabilityCapabilityState | undefinedundefinedThe raw capability state object.
loadingbooleantruetrue until the initial status check completes.
errorError | nullnullCaptured network or validation error (if any).

Fail-Open Behavior

useCapability is designed with fail-open defaults. If network connectivity to RuntimeHQ is interrupted, isOperational remains true and isOutage remains false, preventing control-plane incidents from breaking your application.

Provider Required

Both useCapability and useRuntimeHQ must be rendered within a <RuntimeHQProvider>, or they will throw a descriptive error.


useRuntimeHQState

A standalone hook to fetch and watch RuntimeHQ status directly without requiring a context provider. Ideal for isolated micro-frontends, embedded widgets, or standalone scripts.

import { useRuntimeHQState } from "@theruntimehq/react";

function StandaloneWidget() {
  const { runtime, loading, error } = useRuntimeHQState({
    runtimeKey: "rt_prod_your_key_here",
    intervalSeconds: 60,
  });

  if (loading || !runtime) return null;
  return <div>Status: {runtime.state}</div>;
}

Options (UseRuntimeHQStateOptions)

OptionTypeRequiredDefaultDescription
runtimeKeystringYes—RuntimeHQ status key.
intervalSecondsnumberNo60Background polling interval in seconds. Defaults to 60 seconds.

Convenience Helpers

Utility checkers to quickly evaluate states on RuntimeResponse objects, CapabilityState objects, or raw state strings.

import { 
  isOperational, 
  isMaintenance, 
  isDegraded, 
  isOutage 
} from "@theruntimehq/react";

Signatures

Each helper accepts RuntimeResponse | CapabilityState | RuntimeState | null | undefined and returns a boolean:

HelperEvaluates to true when
isOperational(input)State is "OPERATIONAL". Returns false if input is null or undefined.
isMaintenance(input)State is "MAINTENANCE".
isDegraded(input)State is "DEGRADED".
isOutage(input)State is "OUTAGE".

Example

import { useRuntimeHQ, isOperational, isMaintenance } from "@theruntimehq/react";

export function SystemNotice() {
  const { runtime } = useRuntimeHQ();

  if (!runtime || isOperational(runtime)) return null;

  if (isMaintenance(runtime)) {
    return <div className="notice-maintenance">Scheduled Maintenance: {runtime.message}</div>;
  }

  return <div className="notice-outage">Attention: {runtime.message}</div>;
}

TypeScript Types

All core TypeScript types can be imported directly from @theruntimehq/react:

import type {
  RuntimeState,
  CapabilityState,
  RuntimeResponse,
  RuntimeHQProviderProps,
  RuntimeHQContextValue,
  UseCapabilityResult,
  UseRuntimeHQStateOptions,
} from "@theruntimehq/react";

RuntimeState

type RuntimeState = "OPERATIONAL" | "MAINTENANCE" | "DEGRADED" | "OUTAGE";

CapabilityState

interface CapabilityState {
  capabilityName: string;
  state: RuntimeState;
  message: string;
}

RuntimeResponse

interface RuntimeResponse {
  applicationId: string;
  state: RuntimeState;
  message: string;
  capabilityStates: CapabilityState[];
  version: number;
  updatedAt: Date;
  dataStatus: "FRESH" | "STALE";
  lastSuccessfulFetchAt: Date;

  hasCapability(name: string): boolean;
  getCapabilityState(name: string): CapabilityState | undefined;
}

On this page