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

@subgames/react

v1.0.0

Published

Official React SDK for sub.games tier-gating

Downloads

77

Readme

@subgames/react

Official React SDK for sub.games tier-gating. Provides typed React bindings around the vanilla JS SDK (@subgames/sdk).

Install

npm install @subgames/react
# or
bun add @subgames/react

React 18+ is required as a peer dependency.

Quick Start

Wrap your app with <SubGamesProvider> and use the useSubGames() hook to access the SDK:

import { SubGamesProvider, useSubGames } from '@subgames/react';

function App() {
  return (
    <SubGamesProvider config={{ gameKey: 'my-game' }}>
      <Game />
    </SubGamesProvider>
  );
}

function Game() {
  const { sdk, loading, error } = useSubGames();

  if (loading || !sdk) return <div>Loading...</div>;

  return <button onClick={() => sdk.promptLogin()}>Login</button>;
}

API

<SubGamesProvider>

Loads the SubGames SDK script and initializes the SDK instance.

| Prop | Type | Default | Description | |------|------|---------|-------------| | config | SubGamesConfig | required | SDK configuration passed to SubGamesSDK.init(). | | scriptUrl | string | https://sdk.sub.games/sdk.js | URL of the SDK script. Override for local dev. |

SubGamesConfig

interface SubGamesConfig {
  gameKey: string;    // Your game's unique key
  apiUrl?: string;    // API base URL (default: https://api.sub.games)
  appUrl?: string;    // App base URL (default: https://sub.games)
  overlay?: boolean;  // Enable floating overlay UI
}

useSubGames()

Returns the SDK context. Must be used within a <SubGamesProvider>.

const { sdk, loading, error } = useSubGames();

| Field | Type | Description | |-------|------|-------------| | sdk | ISubGamesSDK \| null | SDK instance. null until loaded. | | loading | boolean | true while the script is loading. | | error | Error \| null | Error if the script failed to load. |

SDK Methods

All methods on sdk are fully typed. These mirror the vanilla JS SDK:

// Player & Auth
sdk.isLoggedIn(): boolean
sdk.getPlayer(): Promise<PlayerInfo | null>
sdk.getToken(): string | null
sdk.setToken(token: string): void
sdk.logout(): void

// Tiers
sdk.getPlayerTier(): Promise<PlayerTier>
sdk.requireTier(tier: PlayerTier, feature?: string): Promise<boolean>

// Prompts
sdk.promptLogin(): Promise<void>
sdk.promptSubscribe(targetTier?: PlayerTier, feature?: string): Promise<void>

// Game State
sdk.pause(): void
sdk.unpause(): void
sdk.isPaused(): boolean

// Events
sdk.on(event, handler): void
sdk.off(event, handler): void

Types

type PlayerTier = 'none' | 'free' | 'supporter' | 'founder';

interface PlayerInfo {
  id: string;
  email: string;
  displayName: string | null;
  avatarUrl: string | null;
}

interface SubGamesEventMap {
  login: () => void;
  logout: () => void;
  tierChange: (tier: PlayerTier) => void;
  pause: () => void;
  unpause: () => void;
}

How It Works

The provider injects the vanilla JS SDK's IIFE script (sdk.js) into the page via a <script> tag. Once loaded, it calls SubGamesSDK.init() with your config and exposes the resulting instance through React context. This means you get the full SDK functionality with zero re-implementation — just typed React bindings on top.