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

@togglely/sdk-react

v1.2.4

Published

React SDK for Togglely - Feature toggles with hooks

Readme

Togglely React SDK

React hooks and components for Togglely feature flag management.

Features

  • 🎣 React Hooks - useToggle, useStringToggle, useNumberToggle, useJSONToggle
  • 🏗️ Components - FeatureToggle, FeatureToggleSwitch for declarative UI
  • SSR Support - Works with Next.js, Remix, and other SSR frameworks
  • 💾 Offline Support - Built-in offline fallback
  • 🔒 TypeScript - Full type safety

Installation

npm install @togglely/sdk-react

Quick Start

import { TogglelyProvider, useToggle, FeatureToggle } from '@togglely/sdk-react';

function App() {
  return (
    <TogglelyProvider 
      apiKey="your-api-key"
      project="my-project"
      environment="production"
      baseUrl="https://togglely.io"
    >
      <MyComponent />
    </TogglelyProvider>
  );
}

function MyComponent() {
  // Using hook
  const isEnabled = useToggle('new-feature', false);
  
  return (
    <div>
      {isEnabled && <NewFeature />}
      
      {/* Or using component */}
      <FeatureToggle toggle="premium-feature" fallback={<FreeVersion />}>
        <PremiumVersion />
      </FeatureToggle>
    </div>
  );
}

Provider Configuration

<TogglelyProvider 
  apiKey="your-api-key"
  project="my-project"
  environment="production"
  baseUrl="https://togglely.io"
  tenantId="brand-a"              // For multi-brand projects
  offlineJsonPath="/toggles.json" // Offline fallback
  initialContext={{ userId: '123' }}
>
  {children}
</TogglelyProvider>

Hooks

useToggle

Check if a boolean feature is enabled:

const isEnabled = useToggle('new-feature', false);

useStringToggle

Get a string value:

const message = useStringToggle('welcome-message', 'Hello!');

useNumberToggle

Get a number value:

const timeout = useNumberToggle('api-timeout', 5000);

useJSONToggle

Get a JSON value:

const config = useJSONToggle('app-config', { theme: 'dark' });

useTogglelyClient

Access the client directly:

const client = useTogglelyClient();
client.setContext({ userId: '123' });

useTogglelyState

Get the current state:

const { isReady, isOffline, lastError } = useTogglelyState();

Components

FeatureToggle

<FeatureToggle 
  toggle="new-feature"
  fallback={<OldVersion />}
  defaultValue={false}
>
  <NewVersion />
</FeatureToggle>

FeatureToggleSwitch

<FeatureToggleSwitch toggle="plan-type" defaultValue="free">
  <FeatureToggleCase when="premium">
    <PremiumFeatures />
  </FeatureToggleCase>
  <FeatureToggleCase when="pro">
    <ProFeatures />
  </FeatureToggleCase>
  <FeatureToggleCase>
    <FreeFeatures />
  </FeatureToggleCase>
</FeatureToggleSwitch>

Server-Side Rendering (SSR)

Next.js App Router

// app/layout.tsx
import { TogglelyProvider } from '@togglely/sdk-react';

export default async function RootLayout({ children }) {
  // Fetch toggles on server
  const response = await fetch(
    `https://togglely.io/sdk/flags/my-project/production?apiKey=${process.env.TOGGLELY_APIKEY}`
  );
  const initialToggles = await response.json();
  
  return (
    <html>
      <body>
        <TogglelyProvider 
          apiKey={process.env.TOGGLELY_APIKEY!}
          project="my-project"
          environment="production"
          baseUrl="https://togglely.io"
          initialToggles={initialToggles}
        >
          {children}
        </TogglelyProvider>
      </body>
    </html>
  );
}

Next.js Pages Router

// pages/index.tsx
import { TogglelyProvider, getTogglelyState } from '@togglely/sdk-react';

export async function getServerSideProps() {
  const initialToggles = await getTogglelyState({
    apiKey: process.env.TOGGLELY_APIKEY!,
    project: 'my-project',
    environment: 'production',
    baseUrl: 'https://togglely.io',
  });
  
  return { props: { initialToggles } };
}

export default function Page({ initialToggles }) {
  return (
    <TogglelyProvider 
      apiKey={process.env.TOGGLELY_APIKEY!}
      project="my-project"
      environment="production"
      baseUrl="https://togglely.io"
      initialToggles={initialToggles}
    >
      <MyComponent />
    </TogglelyProvider>
  );
}

Build-Time JSON Generation

Generate offline JSON during build:

{
  "scripts": {
    "build": "togglely-pull --apiKey=$TOGGLELY_APIKEY --project=my-project --environment=production --output=./public/toggles.json && next build"
  }
}

Then use in your app:

<TogglelyProvider 
  apiKey="your-api-key"
  project="my-project"
  environment="production"
  baseUrl="https://togglely.io"
  offlineJsonPath="/toggles.json"
>

License

MIT