Overview
The feature flags toolkit for Next.js
From the creators of Next.js, the Flags SDK is a free open-source library that gives you the tools you need to use feature flags in Next.js applications.
- Works with any flag provider, custom setups or no flag provider at all
- Compatible with App Router, Pages Router, and Edge Middleware
- Built for feature flags and experimentation
Usage example
-
Declare a new feature flag using the
flag
function:import { flag } from '@vercel/flags/next';export const exampleFlag = flag({key: "example-flag",decide() {// this flag will be on for 50% of visitorsreturn Math.random() > 0.5;}}); -
Use the flag by calling it like any other async function.
await exampleFlag()
This demo flag is on for 50% of visitors. Click Reload Page to see the flag in action.
Aside from the dynamic usage shown in this primitive example, the Flags SDK can handle advanced use cases like targeting individual users, or using feature flags without layout shift while keeping pages fully static.
See the Quickstart guide to learn more.