Skip to main content

Next.js SDK API Reference

Complete API documentation for the Next.js SDK.

Provider Props

PropTypeRequiredDescription
connectionConnectOptions | nullYesConnection options (see below), or null to skip connection
defaultsRecord<string, unknown>NoDefault values if server is unavailable
contextRecord<string, unknown>NoDefault context for override evaluations
snapshotReplaneSnapshotNoSnapshot for SSR hydration
loggerReplaneLoggerNoCustom logger (default: console)

Connection Options

OptionTypeRequiredDescription
baseUrlstringYesReplane server URL
sdkKeystringYesSDK key for authentication
connectTimeoutMsnumberNoSDK connection timeout (default: 5000)
requestTimeoutMsnumberNoTimeout for SSE requests (default: 2000)
retryDelayMsnumberNoBase delay between retries (default: 200)
inactivityTimeoutMsnumberNoSSE inactivity timeout (default: 30000)
fetchFntypeof fetchNoCustom 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
})