SDK 2.0 is in beta. Until it’s released, install the @beta tag, as below.
You’ll need a Flaggish account and a Next.js app using the App Router. No account yet? Get early access.
Create a flag
In the dashboard, open your project and add a flag called
new-checkout. Leave it switched off for now.Install the SDK
Terminalnpm i @flaggish/sdk@betaAdd 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.localNEXT_PUBLIC_FLAGGISH_CLIENT_KEY=your-client-keyAdd 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.tsimport { flaggishMiddleware } from '@flaggish/sdk/next'; import type { NextRequest } from 'next/server'; export function proxy(request: NextRequest) { return flaggishMiddleware(request); }middleware.tsimport { flaggishMiddleware } from '@flaggish/sdk/next'; import type { NextRequest } from 'next/server'; export function middleware(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.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.tsximport { 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 withcacheComponentsturned on, and harmless otherwise. Why Suspense is neededCheck the flag
In a server component,
getFlagreturnstrueorfalse. In client components, useuseFlag.app/checkout/page.tsximport { 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 withcacheComponents, where navigating between pages doesn’t use the one in the root layout. WithoutcacheComponents, the page can callgetFlagdirectly.app/checkout/checkout-button.tsx'use client'; import { useFlag } from '@flaggish/sdk/react'; export function CheckoutButton() { const newCheckout = useFlag('new-checkout'); return <button>{newCheckout ? 'Buy now' : 'Add to basket'}</button>; }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 devreads your Development flags and a production build reads Production, so switch the flag in the environment you’re running.
You’ll need a Flaggish account and a React app. This runs in the browser only; for server rendering, use the Next.js setup.
Install the SDK
Terminalnpm i @flaggish/sdk@betaAdd the provider
Wrap your app in
FlaggishProviderwith the client key from Settings › API keys. The key is safe in the browser.defaultsare used until the flags load, and if Flaggish can’t be reached.App.tsximport { FlaggishProvider } from '@flaggish/sdk/react'; export const App = () => ( <FlaggishProvider clientKey="your-client-key" defaults={{ 'new-checkout': false }}> <Page /> </FlaggishProvider> );Check the flag
useFlagreturnstrueorfalse.useFlagstells you whether the flags are still loading.Page.tsximport { useFlag, useFlags } from '@flaggish/sdk/react'; export const Page = () => { const enabled = useFlag('new-checkout'); const { isLoading } = useFlags(); if (isLoading) return null; return enabled ? <NewCheckout /> : <OldCheckout />; };Flip it
Turn new-checkout on in the dashboard.Reload the page: the new version appears within 30 seconds.
You’ll need a Flaggish account and a Node project: a script, a worker or any other server.
Install the SDK
Terminalnpm i @flaggish/sdk@betaAdd your client key
Copy the client key from Settings › API keys. The SDK reads
developmentflags unlessNODE_ENVisproduction..envFLAGGISH_CLIENT_KEY=your-client-keyCheck the flag
Pass a
userIdso the same person always gets the same answer in a rollout.index.tsimport { createFlaggish } from '@flaggish/sdk'; const flaggish = createFlaggish({ clientKey: process.env.FLAGGISH_CLIENT_KEY }); if (await flaggish.isEnabled('new-checkout', { userId: 'user_123' })) { // ... } const all = await flaggish.getAll({ userId: 'user_123' });Flip it
Turn new-checkout on in the dashboard.The next check after the 30-second cache expires returns
true.