Logokeyset
  • Product
  • Pricing
  • Docs
  • Contact
LoginGet Started
keyset
Navigation
  • Product
  • Pricing
  • Docs
  • Contact
Login to AccountGet Started Free
keyset

A powerful configuration and content management system for modern applications.

Product

  • Features
  • Pricing
  • Use Cases
  • Documentation

Company

  • About
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Follow Us

TwitterGitHub

© 2026 Keyset. All rights reserved.

Logokeyset
  • Product
  • Pricing
  • Docs
  • Contact
LoginGet Started
keyset
Navigation
  • Product
  • Pricing
  • Docs
  • Contact
Login to AccountGet Started Free
Docs/Reference/React Integration
Getting Started
Reference
  • Configuration
  • Content API
  • React Integration
  • TypeScript Types
Guides

React Integration

The React layer is exported from a separate entry point to keep the core SDK tree-shakeable:

TypeScript
import { KeysetProvider, useContent, useKeysetBoolean } from "keysetapp/react";

Setup — KeysetProvider

Wrap your application (or the subtree that needs remote config) with KeysetProvider. It creates a single Keyset client and makes it available to all child components via React context.

TypeScript JSX
import { KeysetProvider } from "keysetapp/react";

const keysetConfig = {
  apiKey: "pkey_your_public_key",
  cacheTTL: 60000,
  cache: { enabled: true, ttl: 60000 },
};

export default function App() {
  return (
    <KeysetProvider config={keysetConfig}>
      <Router />
    </KeysetProvider>
  );
}

Props

PropTypeRequiredDescription
configKeysetConfigYesSame config object accepted by new Keyset(config). See Configuration.
childrenReact.ReactNodeYesYour component tree.

The client is memoized and only re-created when apiKey, baseUrl, retries, or timeout change.


useKeyset()

Returns the raw Keyset client instance from context. Use this when you need direct access to the client — for example, to call write methods.

TypeScript JSX
import { useKeyset } from "keysetapp/react";

function AdminPanel() {
  const client = useKeyset();

  const handleCreate = async () => {
    await client.content.create({ key: "feature_x", value: true, type: "boolean" });
  };

  return <button onClick={handleCreate}>Enable Feature X</button>;
}

Returns — Keyset client instance.

Throws — "useKeyset must be used inside Keyset Provider" if called outside KeysetProvider.


useContent(options?)

Fetches all remote config entries and exposes them with loading/error state.

TypeScript JSX
import { useContent } from "keysetapp/react";

function ConfigPanel() {
  const { data, loading, error, refetch } = useContent();

  if (loading) return <p>Loading config…</p>;
  if (error)   return <p>Failed to load: {error}</p>;

  return (
    <>
      <pre>{JSON.stringify(data, null, 2)}</pre>
      <button onClick={refetch}>Refresh</button>
    </>
  );
}

Options

OptionTypeDefaultDescription
autoFetchbooleantrueFetch automatically on mount. Set to false to fetch manually via refetch.

Returns

PropertyTypeDescription
dataRecord<string, unknown>All remote config entries as a flat key-value map. {} until loaded.
loadingbooleantrue while fetching.
errorstring | nullError message if the request failed, otherwise null.
refetch() => Promise<void>Trigger a fresh fetch manually.

Manual fetch example

TypeScript JSX
const { data, loading, refetch } = useContent({ autoFetch: false });

// Fetch on user action
return <button onClick={refetch}>Load Config</button>;

useContentKey<T>(key)

Returns the value of a single key from the flat content map. Internally calls useContent(), so all entries are fetched.

TypeScript JSX
import { useContentKey } from "keysetapp/react";

function HeroBanner() {
  const { value, loading, error } = useContentKey<string>("hero_title");

  if (loading) return <p>Loading…</p>;
  return <h1>{value ?? "Welcome"}</h1>;
}

Parameters

ParamTypeDescription
keystringThe config key to retrieve.

Returns

PropertyTypeDescription
valueT | undefinedThe value cast to T, or undefined if the key does not exist.
loadingbooleantrue while fetching.
errorstring | nullError message or null.
refetch() => Promise<void>Re-fetch all content.

Typed hooks

These hooks fetch only the single key they need and return a strongly-typed value. They all follow the same { value, loading } return shape.

useKeysetString(key, defaultValue?)

TypeScript JSX
import { useKeysetString } from "keysetapp/react";

function Headline() {
  const { value, loading } = useKeysetString("hero_title", "Welcome");

  return loading ? <span>…</span> : <h1>{value}</h1>;
}
ParamTypeDefault
keystring—
defaultValuestring""

Returns { value: string; loading: boolean }


useKeysetNumber(key, defaultValue?)

TypeScript JSX
const { value: limit, loading } = useKeysetNumber("max_results", 10);
ParamTypeDefault
keystring—
defaultValuenumber0

Returns { value: number; loading: boolean }


useKeysetBoolean(key, defaultValue?)

Ideal for feature flags.

TypeScript JSX
import { useKeysetBoolean } from "keysetapp/react";

function NewDashboard() {
  const { value: isEnabled, loading } = useKeysetBoolean("new_dashboard", false);

  if (loading || !isEnabled) return <OldDashboard />;
  return <NewDashboardComponent />;
}
ParamTypeDefault
keystring—
defaultValuebooleanfalse

Returns { value: boolean; loading: boolean }


useKeysetJSON<T>(key, defaultValue?)

Returns a parsed, fully-typed JSON value.

TypeScript JSX
interface NavLink { label: string; href: string }

const { value: links } = useKeysetJSON<NavLink[]>("nav_links", []);
ParamTypeDefault
keystring—
defaultValueT | nullnull

Returns { value: T | null; loading: boolean }


useKeysetURL(key, defaultValue?)

Returns a URL string entry (type must be "url").

TypeScript JSX
const { value: docsUrl } = useKeysetURL("docs_link", "https://docs.example.com");
ParamTypeDefault
keystring—
defaultValuestring""

Returns { value: string; loading: boolean }


useKeysetImage(key, defaultValue?)

Returns an image URL string entry (type must be "image").

TypeScript JSX
const { value: logoUrl } = useKeysetImage("logo", "/logo.png");

return <img src={logoUrl} alt="Logo" />;
ParamTypeDefault
keystring—
defaultValuestring""

Returns { value: string; loading: boolean }


Choosing the right hook

ScenarioHook
Feature flag (on/off)useKeysetBoolean
Text / copyuseKeysetString
Numeric config valueuseKeysetNumber
Complex object / arrayuseKeysetJSON<T>
External linkuseKeysetURL
Logo / banner imageuseKeysetImage
Untyped access to any keyuseContentKey<T>
Access to all keys at onceuseContent
Direct client accessuseKeyset
PreviousContent API
NextTypeScript Types

Use with AI

Copy the full Keyset SDK reference as a ready-to-use AI prompt. Paste it into any AI tool to get instant, accurate integration help.

Resources

  • FAQ
  • Privacy Policy
keyset

A powerful configuration and content management system for modern applications.

Product

  • Features
  • Pricing
  • Use Cases
  • Documentation

Company

  • About
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Follow Us

TwitterGitHub

© 2026 Keyset. All rights reserved.