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

mock-state-toggle

v0.1.0

Published

Cookie-based mock API state toggle for Next.js development — floating orange button that persists test states via cookies

Readme

mfx-mock-state-toggle

A floating dev-only toggle for Next.js that persists mock API states via cookies. Useful for testing different UI states (empty lists, error states, role-based views) without modifying code.

  • Orange floating button (bottom-right) — only visible in non-production
  • Cookie-based state persistence — survives page reloads
  • Route-aware — shows relevant states for the current page
  • Keyboard shortcut — Ctrl+Shift+M clears all states

Quick start

pnpm add mfx-mock-state-toggle
// src/app/layout.tsx
import { MockToggleLoader } from 'mfx-mock-state-toggle';
import { ROUTE_CONFIGS } from '@/config/mockRouteConfigs';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <MockToggleLoader routeConfigs={ROUTE_CONFIGS} />
      </body>
    </html>
  );
}
// src/config/mockRouteConfigs.ts
import type { RouteConfig } from 'mfx-mock-state-toggle';

export const ROUTE_CONFIGS: RouteConfig[] = [
  {
    pattern: '/users',
    exact: true,
    config: {
      moduleName: 'Users',
      states: [
        { key: 'emptyUserList', label: 'Empty List', description: 'No users', category: 'list' },
        { key: 'errorUserList', label: 'Error', description: 'Load error', category: 'list' },
      ],
    },
  },
];
// src/app/api/users/route.ts
import { cookies } from 'next/headers';
import { hasMockState, MOCK_API_STATES_COOKIE } from 'mfx-mock-state-toggle';

export async function GET() {
  const mock = (await cookies()).get(MOCK_API_STATES_COOKIE)?.value;
  if (hasMockState(mock, 'emptyUserList')) return Response.json({ users: [] });
  if (hasMockState(mock, 'errorUserList')) return Response.json({ error: '...' }, { status: 500 });
  return Response.json({ users: await db.getUsers() });
}

Hidden automatically when NEXT_PUBLIC_MODE=production.


Docs

| File | Contents | |---|---| | INTEGRATION.md | Full setup guide — all required files and config | | LOCAL-DEV.md | Symlinking for local development across projects | | PUBLISHING.md | How to publish to npm |


Exports

| Export | Type | Use | |---|---|---| | MockToggleLoader | Component | Mount in root layout | | MockStateToggle | Component | Use directly with a config (no route detection) | | useMockStateToggle | Hook | Build a custom toggle UI | | getConfigForRoute | Function | Match a pathname against route configs | | hasMockState | Function | Check active states server-side | | MOCK_API_STATES_COOKIE | Constant | Cookie name for reading/writing states | | API_SIMULATION_TIMEOUT | Constant | Default timeout (500ms) for mock delays | | isProductionEnvironment | Function | Returns true when NEXT_PUBLIC_MODE=production | | MockStateConfig | Type | Config shape for a module | | MockStateOption | Type | Individual mock state definition | | RouteConfig | Type | Route-to-config mapping |


Requirements

  • Next.js ≥ 14
  • React ≥ 18
  • Tailwind CSS (v3 or v4)