惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
D
DataBreaches.Net
P
Proofpoint News Feed
小众软件
小众软件
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
雷峰网
雷峰网
G
Google Developers Blog

Flags SDK Documentation

Global Config Bulk Evaluation Evaluation Context Precompute GrowthBook Hypertune PostHog Split Evaluation Context Precompute Evaluation Context Quickstart Precompute GrowthBook Hypertune PostHog Split Proxy Dashboard Pages Marketing Pages Dashboard Pages Marketing Pages Data Locality Providers LaunchDarkly Optimizely Reflag Statsig Server-side vs Client-side Flags as Code
Quickstart
Vercel · 2026-05-28 · via Flags SDK Documentation

Learn how to start using the Flags SDK in your Next.js project.

From the creators of Next.js, the Flags SDK is a free open-source library for implementing feature flags and A/B tests in your applications.

  • Works with any flag provider or custom setup.
  • Compatible with App Router, Pages Router, and Middleware.

Install the Flags SDK using your preferred package manager:

If you use an AI coding assistant, we recommend installing the Flags SDK agent skill:

npx skills add vercel/flags --skill flags-sdk

Create a flags.ts file in your project and declare a feature flag there:

import { flag } from 'flags/next';

export const exampleFlag = flag({
  key: 'example-flag',
  decide() {
    return Math.random() > 0.5;
  },
});

This produces an exampleFlag function.

If you're using the App Router, you can call the flag function from a page, component, or middleware to evaluate the flag.

import { exampleFlag } from '../flags';

export default async function Page() {
  const example = await exampleFlag();

  return <div>{example ? 'Flag is on' : 'Flag is off'}</div>;
}

That's it! Run next dev and open your browser to see the "Flag is on" or "Flag is off" text.

Pages Router

If you're using the Pages Router, you can call the flag function inside getServerSideProps and pass the values to the page as props.

import type { InferGetServerSidePropsType, GetServerSideProps } from 'next'
import { exampleFlag } from '../flags';

export const getServerSideProps = (async ({ req }) => {
  const example = await exampleFlag(req);
  return { props: { example } };
}) satisfies GetServerSideProps<{ example: boolean }>;

export default function Page({
  example
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
  return <div>{example ? 'Flag is on' : 'Flag is off'}</div>;
}

That's it! Run next dev and open your browser to see the "Flag is on" or "Flag is off" text.

The Flags Explorer is a feature of the Vercel Toolbar which allows overriding feature flags for your session only, without affecting your team members. The Flags SDK will automatically respect overrides set by the Flags Explorer.

This is useful when working with feature flags, as you can try out different states without actually changing the feature flag configuration in the flag provider.

Learn more about precompute in Next.js

Clone the Flags SDK example