This example demonstrates how to use @replanejs/next with Next.js App Router (React Server Components).
- Server-side config fetching with
ReplaneRoot - Client hydration with no flash of unstyled content
- Real-time config updates via SSE
- Full TypeScript support with typed hooks
-
Copy the environment file:
cp .env.example .env.local
-
Update the environment variables with your Replane credentials.
-
Install dependencies:
pnpm install
-
Run the development server:
pnpm dev
import { ReplaneRoot } from "@replanejs/next/server";
export default async function RootLayout({ children }) {
return (
<html>
<body>
<ReplaneRoot
options={{
baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
}}
>
{children}
</ReplaneRoot>
</body>
</html>
);
}"use client";
import { useConfig } from "@replanejs/next";
export function MyComponent() {
const theme = useConfig("theme");
return <div>{theme.darkMode ? "Dark" : "Light"}</div>;
}- ReplaneRoot: Server component that fetches configs and provides them to children
- Hooks: Use
useConfiganduseReplanein client components - Environment variables: Use
NEXT_PUBLIC_prefix so variables are available on both server and client