Using Bucket with Next.js is straightforward. You can use the @bucketco/node-sdk on the server or @bucketco/react-sdk in the browser. Handling feature targeting server-side is often advantageous because it removes the need for additional handling of loading states.
Server-side Rendering (SSR)
It's often advantageous to use Server-side Rendering when possible because it can help avoid extra loading screens while your Bucket features are loading.
For pages that use server-side rendering, use the @bucketco/node-sdk in the following manner. Create a new file called bucket.ts and adjust it to your needs:
The experimental @vercel/flags SDK is a Next.js oriented interface for server-side feature flags. It's straight forward to use with the Bucket Node.js SDK:
import { unstable_flag as flag } from'@vercel/flags/next';import { getFeature } from"@/app/bucket";exportconsthuddles=flag({ key:'huddles',asyncdecide() {returngetFeature(this.key).isEnabled; },});
Client-side Rendering
Use @bucketco/react-sdk with Next.js client-side rendering like so: