This example demonstrates how to use @replanejs/next with Next.js Pages Router.
- Server-side config fetching via getServerSideProps
- Static generation with ISR via getStaticProps
- 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
/- Server-side rendering with getServerSideProps/static- Static generation with ISR (getStaticProps)
import { ReplaneProvider, type ReplaneSnapshot } from "@replanejs/next";
export default function App({ Component, pageProps }) {
return (
<ReplaneProvider
snapshot={pageProps.replaneSnapshot}
connection={{
baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
}}
>
<Component {...pageProps} />
</ReplaneProvider>
);
}import { getReplaneSnapshot } from "@replanejs/next";
export const getServerSideProps = async () => {
const snapshot = await getReplaneSnapshot({
connection: {
baseUrl: process.env.REPLANE_BASE_URL!,
sdkKey: process.env.REPLANE_SDK_KEY!,
},
});
return {
props: { replaneSnapshot: snapshot },
};
};import { getReplaneSnapshot } from "@replanejs/next";
export const getStaticProps = async () => {
const snapshot = await getReplaneSnapshot({
connection: {
baseUrl: process.env.REPLANE_BASE_URL!,
sdkKey: process.env.REPLANE_SDK_KEY!,
},
});
return {
props: { replaneSnapshot: snapshot },
revalidate: 60, // ISR: revalidate every 60 seconds
};
};import { useConfig } from "@replanejs/next";
export function MyComponent() {
const theme = useConfig("theme");
return <div>{theme.darkMode ? "Dark" : "Light"}</div>;
}- Single import: Use
@replanejs/nextfor all imports - Environment variables: Use
NEXT_PUBLIC_prefix for client-side variables - Snapshot: Pass
snapshotfrom SSR to hydrate the client without flicker