Next.js SDK API Reference
Complete API documentation for the Next.js SDK.
Provider Props
| Prop | Type | Required | Description |
|---|---|---|---|
connection | ConnectOptions | null | Yes | Connection options (see below), or null to skip connection |
defaults | Record<string, unknown> | No | Default values if server is unavailable |
context | Record<string, unknown> | No | Default context for override evaluations |
snapshot | ReplaneSnapshot | No | Snapshot for SSR hydration |
logger | ReplaneLogger | No | Custom logger (default: console) |
Connection Options
| Option | Type | Required | Description |
|---|---|---|---|
baseUrl | string | Yes | Replane server URL |
sdkKey | string | Yes | SDK key for authentication |
connectTimeoutMs | number | No | SDK connection timeout (default: 5000) |
requestTimeoutMs | number | No | Timeout for SSE requests (default: 2000) |
retryDelayMs | number | No | Base delay between retries (default: 200) |
inactivityTimeoutMs | number | No | SSE inactivity timeout (default: 30000) |
fetchFn | typeof fetch | No | Custom fetch implementation |
See the JavaScript SDK documentation for more details.
Components
ReplaneRoot
Server component for App Router. Fetches configs on the server and provides them to the app.
<ReplaneRoot<AppConfigs>
connection={{
baseUrl: string;
sdkKey: string;
}}
>
{children}
</ReplaneRoot>
ReplaneProvider
Client-side provider for Pages Router or custom setups.
<ReplaneProvider
snapshot={replaneSnapshot}
connection={{
baseUrl: string;
sdkKey: string;
}}
>
{children}
</ReplaneProvider>
Hooks
useConfig
Returns the value of a config. Re-renders when the config changes.
const theme = useConfig<{ darkMode: boolean }>('theme')
useReplane
Returns the Replane client instance.
const client = useReplane<AppConfigs>()
const snapshot = client.getSnapshot()
const theme = client.get('theme')
createConfigHook
Creates a typed version of useConfig.
const useAppConfig = createConfigHook<AppConfigs>()
const theme = useAppConfig('theme') // Fully typed
createReplaneHook
Creates a typed version of useReplane.
const useAppReplane = createReplaneHook<AppConfigs>()
const client = useAppReplane()
Functions
getReplaneSnapshot
Fetches a snapshot of all configs. Use in getServerSideProps, getStaticProps, or getInitialProps.
const snapshot = await getReplaneSnapshot<AppConfigs>({
connection: {
baseUrl: process.env.REPLANE_BASE_URL!,
sdkKey: process.env.REPLANE_SDK_KEY!
},
// by default, getReplaneSnapshot will reuse the created client for 60 seconds
// for fast subsequent calls, the client will be syncing with the server
// in the background during this time
keepAliveMs: 60_000
})