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

@splitlab/react

v0.11.0

Published

React bindings for SplitLab A/B testing and feature flags

Readme

@splitlab/react

React hooks and providers for SplitLab A/B testing and feature flags. Wraps @splitlab/js-client with a React-friendly API.

Installation

npm install @splitlab/react

Quick Start

import { SplitLabProvider, useVariant, useFeatureFlag } from '@splitlab/react';

function App() {
  return (
    <SplitLabProvider config={{
      apiKey: 'ot_live_abc123',
      baseUrl: 'https://splitlab.cc',
    }}>
      <CheckoutPage />
    </SplitLabProvider>
  );
}

function CheckoutPage() {
  const variant = useVariant('checkout-btn');   // 'control' | 'variant_a' | null
  const darkMode = useFeatureFlag('dark-mode'); // true | false

  return (
    <div className={darkMode ? 'dark' : ''}>
      {variant === 'variant_a' ? <GreenButton /> : <BlueButton />}
    </div>
  );
}

Providers

<SplitLabProvider>

Initializes the SDK client and provides it to the component tree. The client fetches config on mount and evaluates experiments/flags locally (< 1ms).

<SplitLabProvider config={{
  apiKey: 'ot_live_abc123',
  baseUrl: 'https://splitlab.cc',
  // All @splitlab/js-client options are supported:
  trackPageviews: true,
  realtimeUpdates: true,
  onConfigUpdate: () => console.log('Config updated'),
}}>
  {children}
</SplitLabProvider>

<SplitLabBootstrapProvider>

For SSR apps. Hydrates the client synchronously from server-generated bootstrap data — no config fetch, no loading flash.

import { SplitLabBootstrapProvider } from '@splitlab/react';
import type { BootstrapData } from '@splitlab/react';

// Bootstrap data generated server-side via @splitlab/node's ctx.getBootstrapData()
const bootstrap: BootstrapData = JSON.parse(window.__SPLITLAB_BOOTSTRAP__);

<SplitLabBootstrapProvider
  config={{ apiKey: 'ot_live_abc123', baseUrl: 'https://splitlab.cc' }}
  bootstrap={bootstrap}
>
  {children}
</SplitLabBootstrapProvider>

Hooks

useVariant(experimentKey): string | null

Returns the assigned variant key, or null if the user is excluded or the SDK is still loading. Fires a $exposure event on first access (once per experiment per client lifetime).

const variant = useVariant('pricing-page');
if (variant === 'annual_first') showAnnualFirst();

useFeatureFlag(flagKey): boolean

Returns true if the flag is enabled, false otherwise (including while loading).

if (useFeatureFlag('new-onboarding')) return <NewOnboarding />;
return <ClassicOnboarding />;

useSplitLab(): SplitLabClient

Returns the underlying client instance for advanced operations (tracking, identity, etc.). Throws if called outside a provider.

const client = useSplitLab();

const handlePurchase = async () => {
  await client.track('purchase', { value: 49.99 });
};

const handleLogin = async (userId: string) => {
  await client.identify(userId);
};

Loading States

Hooks return safe defaults while the SDK initializes:

  • useVariant() returns null (control / no treatment)
  • useFeatureFlag() returns false (off)

Use <SplitLabBootstrapProvider> to eliminate loading states entirely in SSR apps.

Building

npm run build   # ESM + CJS + types → dist/
npm run dev     # Watch mode