This is an example app that uses Reforge, TypeScript and Next.js.
This example demonstrates key Reforge SDK features for Next.js applications:
- Automatic type generation from your Reforge configuration using
reforge generate --targets react-ts - Type-safe feature flag access with full IntelliSense support
- Generated client types in
src/app/types/including:reforge-client-types.d.ts- TypeScript declarations for your flagsreforge-client.ts- Type-safe React hooks and client wrapper
- Context initialization with user attributes on the server
- Flag extraction using
reforge.extract()for hydration - Environment variable configuration with
NEXT_PUBLIC REFORGE_FRONTEND_SDK_KEY
- Seamless client-side takeover using
ReforgeProvider - Initial flag state passed from server to prevent hydration mismatches
- Typesafe React hook providing type-safe flag access via generated methods
The app demonstrates two feature flags:
sample.boolean.flag(boolean) - Simple boolean flagsample.json.config(object) - JSON configuration object using a JSON validation schema in reforge
To install the dependencies, run:
npm installFirst, run the development server:
npm run devOpen http://localhost:3000 with your browser to see the result.
src/app/layout.tsx- Server-side Reforge initialization and flag extractionsrc/app/page.tsx- Client-side flag consumption using generated hookssrc/app/components/WrappedReforgeProvider.tsx- React context provider setupsrc/app/types/- Generated TypeScript types and hooksreforge.config.json- Configuration for type generation