Quickstart

Add Flaggish to a Next.js app and flip your first flag from the dashboard, without a redeploy.

SDK 2.0 is in beta. Until it’s released, install the @beta tag, as below.

About 5 minutesNext.js 14, 15 and 16

You’ll need a Flaggish account and a Next.js app using the App Router. No account yet? Get early access.

  1. Create a flag

    In the dashboard, open your project and add a flag called new-checkout. Leave it switched off for now.

  2. Install the SDK

    Terminal
    npm i @flaggish/sdk@beta
  3. Add your client key

    Copy the client key from Settings › API keys and add it to .env.local. It’s safe in the browser: it can read flags, never change them.

    .env.local
    NEXT_PUBLIC_FLAGGISH_CLIENT_KEY=your-client-key
  4. Add the proxy

    The proxy gives each visitor an anonymous ID, so logged-out users get the same answer on the server and in the browser.

    proxy.ts
    import { flaggishMiddleware } from '@flaggish/sdk/next';
    import type { NextRequest } from 'next/server';
    
    export function proxy(request: NextRequest) {
      return flaggishMiddleware(request);
    }

    Put it at the project root, or in src/ if you use one. Using Clerk or another middleware? Combine them.

  5. Wrap your app

    Add the provider to your root layout. It loads your flags on the server, so nothing flickers on first paint.

    app/layout.tsx
    import { FlaggishServerProvider } from '@flaggish/sdk/next';
    import { Suspense } from 'react';
    
    export default function RootLayout({ children }: { children: React.ReactNode }) {
      return (
        <html lang="en">
          <body>
            <Suspense>
              <FlaggishServerProvider>{children}</FlaggishServerProvider>
            </Suspense>
          </body>
        </html>
      );
    }

    The <Suspense> boundary is required on Next.js 16 with cacheComponents turned on, and harmless otherwise. Why Suspense is needed

  6. Check the flag

    In a server component, getFlag returns true or false. In client components, use useFlag.

    app/checkout/page.tsx
    import { getFlag } from '@flaggish/sdk/next';
    import { Suspense } from 'react';
    
    export default function CheckoutPage() {
      return (
        <Suspense fallback={<p>Loading…</p>}>
          <CheckoutSwitch />
        </Suspense>
      );
    }
    
    async function CheckoutSwitch() {
      const newCheckout = await getFlag('new-checkout');
      return newCheckout ? <NewCheckout /> : <Checkout />;
    }

    The page’s own <Suspense> is for Next.js 16 with cacheComponents, where navigating between pages doesn’t use the one in the root layout. Without cacheComponents, the page can call getFlag directly.

  7. Flip it

    Turn new-checkout on in the dashboard.

    Reload your page: the new checkout appears within 30 seconds. No redeploy, no code change.

    next dev reads your Development flags and a production build reads Production, so switch the flag in the environment you’re running.

Next steps

Was this page helpful?

Request early access

Become a beta user, or stay up to date with the project.