Menu

Declaring feature flags in code - Vercel
📰

Declaring feature flags in code - Vercel

Vercel News·Dominik Ferber·2 days ago
#ZNaBmhKt
#vercel#feature#flags#flag#pattern
Reading 0:00
15s threshold

We’re introducing a new approach for working with feature flags. This approach allows declaring feature flags in code and calling them as functions. Flags implemented using this pattern can automatically respect overrides set by the Vercel Toolbar, and integrate with our Developer Experience Platform features like Web Analytics and Runtime Logs.

import { unstable_flag as flag } from "@vercel/flags/next"

const showSummerSale = flag ( {

key : "summer-sale" ,

decide : async ( ) => false

} )

Declaring a feature flag

The pattern avoids common pitfalls of client-side feature flag and experimentation usage, such as flashing the wrong experiment, loading spinners, layout shift, and jank. It works with any feature flag provider and even custom setups.

export const showSummerSale = flag < boolean > ( {

key : 'summer-sale' ,

async decide ( ) {

return getLaunchDarklyClient ( ) . variation ( this .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.