Skip to content

React Adapter API

Terminal window
npm install @rep-protocol/react @rep-protocol/sdk
function useRep(key: string): string | undefined;
function useRep(key: string, defaultValue: string): string;

Reads a PUBLIC tier variable. Synchronous, hot-reload-aware.

ParameterTypeDescription
keystringVariable name (e.g., 'API_URL')
defaultValuestringOptional fallback value

Returns: string | undefined (or string if defaultValue provided).

Behavior:

  • Reads from the injected payload immediately (no loading state)
  • Subscribes to hot reload in useEffect
  • Unsubscribes on unmount
  • Re-renders component when the variable changes
function useRepSecure(key: string): {
value: string | null;
loading: boolean;
error: Error | null;
};

Reads a SENSITIVE tier variable. Async — fetches a session key on first call.

ParameterTypeDescription
keystringVariable name (e.g., 'ANALYTICS_KEY')

Returns: { value, loading, error } state object.

Behavior:

  • Initial state: { value: null, loading: true, error: null }
  • Success: { value: '...', loading: false, error: null }
  • Failure: { value: null, loading: false, error: Error }
  • Decrypted value is cached for the page lifetime
  • Re-fetches if key changes
  • Cleans up on unmount (cancelled flag prevents state update after unmount)
  • React >= 16.8
  • @rep-protocol/sdk peer dependency