npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@myflags/next

v0.3.0

Published

Next.js bindings for MyFlags SDK

Readme

@myflags/next

Next.js bindings for MyFlags SDK. This package provides Next.js-specific functionality for feature flag management, including SSR support and automatic revalidation.

Installation

npm install @myflags/next
# or
yarn add @myflags/next
# or
pnpm add @myflags/next

Quick Start

First, wrap your application with the MyFlagsProvider:

// app/layout.tsx
import { MyFlagsProvider } from "@myflags/next/client";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <MyFlagsProvider
      config={{
        apiKey: "your-api-key",
        projectId: "your-project-id",
        environment: "production",
        retryCount: 3, // Optional, defaults to 3 retries
        retryDelay: 1000, // Optional, delay between retries in milliseconds
      }}
    >
      {children}
    </MyFlagsProvider>
  );
}

Or with combination with the server side initial flags rendering:

// app/page.tsx
import { type MyFlagsConfig } from "@myflags/next";
import { getServerSideFlags } from "@myflags/next/server";
import { MyFlagsProvider } from "@myflags/next/client";

const config: MyFlagsConfig = {
  apiKey: "your-api-key",
  projectId: "your-project-id",
  environment: "production",
  retryCount: 3, // Optional, defaults to 3 retries
  retryDelay: 1000, // Optional, delay between retries in milliseconds
};

export default async function Page() {
  const defaultFlags = await getServerSideFlags(config);

  return (
    <MyFlagsProvider defaultFlags={defaultFlags} config={config}>
      {children}
    </MyFlagsProvider>
  );
}

Usage

Client-side Components

"use client";

import { useFlag, useFlags } from "@myflags/next/client";

function MyComponent() {
  // Get a single flag
  const isNewFeatureEnabled = useFlag("new_feature");

  // Or get all flags
  const flags = useFlags();

  return (
    <div>
      {isNewFeatureEnabled && <NewFeatureComponent />}
      {/* or */}
      {flags.newFeature && <NewFeatureComponent />}
    </div>
  );
}

Server Components (App Router)

import { getServerSideFlags } from "@myflags/next/server";

export default async function Page() {
  const flags = await getServerSideFlags({
    apiKey: "your-api-key",
    projectId: "your-project-id",
    environment: "production",
    retryCount: 3, // Optional, defaults to 3 retries
    retryDelay: 1000, // Optional, delay between retries in milliseconds
  });

  return <div>{flags.newFeature && <NewFeatureComponent />}</div>;
}

API Routes

import { getApiFlags } from "@myflags/next/server";

export default async function handler(req, res) {
  const flags = await getApiFlags({
    apiKey: "your-api-key",
    projectId: "your-project-id",
    environment: "production",
    retryCount: 3, // Optional, defaults to 3 retries
    retryDelay: 1000, // Optional, delay between retries in milliseconds
  });

  res.status(200).json(flags);
}

Configuration

The configuration object accepts the following properties:

interface MyFlagsConfig {
  apiKey: string;
  projectId: string;
  environment: string;
  refreshInterval?: number; // Optional, defaults to 10 minutes (600000ms)
  retryCount?: number; // Optional, defaults to 3 retries for failed API requests
  retryDelay?: number; // Optional, defaults to 1000ms delay between retries
}

Features

  • SSR Support: Works seamlessly with Next.js server-side rendering
  • Automatic Revalidation: Flags are automatically updated when changes occur
  • Type Safety: Full TypeScript support
  • Efficient Caching: Server-side caching to minimize API calls
  • React Hooks: Easy-to-use hooks for client-side components
  • App Router Support: Compatible with Next.js App Router
  • Pages Router Support: Compatible with Next.js Pages Router

API Reference

Hooks

useFlag(key: string, defaultValue?: boolean)

Returns the value of a single flag.

const isEnabled = useFlag("feature-key", false);

useFlags()

Returns all flags.

const flags = useFlags();

Server Functions

getServerSideFlags(config: MyFlagsConfig)

Retrieves flags on the server side.

const flags = await getServerSideFlags(config);

getApiFlags(config: MyFlagsConfig)

Retrieves flags in API routes.

const flags = await getApiFlags(config);

Components

MyFlagsProvider

Provider component that manages the flags state.

<MyFlagsProvider config={config}>{children}</MyFlagsProvider>

License

MIT