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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@malahimdev/global-state

v1.2.1

Published

Tiny global state manager for React/Next.js

Readme

🌍 @malahimdev/global-state

⚡ Tiny, zero-boilerplate global state manager for React & Next.js — inspired by Zustand.
No Context. No Providers. 100% TypeScript. React 18+ ready.


🚀 Features

  • 🧠 Zustand-like API – create multiple global stores with ease
  • ⚙️ No Providers needed – works directly with useSyncExternalStore
  • 🧩 Tiny & Fast – less than 1KB gzipped
  • 💙 TypeScript first – full type inference
  • 🌈 Works in Next.js App Router – perfect for modern projects

📦 Installation

npm install @malahimdev/global-state
# or
yarn add @malahimdev/global-state

🧠 Basic Usage

1️⃣ Create a Store

Create your store inside /store/counter.ts:

"use client";
import { createGlobalStore } from "@malahimdev/global-state";

interface CounterState {
  count: number;
}

export const counterStore = createGlobalStore<CounterState>({
  count: 0,
});

2️⃣ Use It Anywhere

You can access or update the state from any component or page:

"use client";
import { counterStore } from "@/store/counter";

export default function CounterPage() {
  const [counter, setCounter] = counterStore.useStore();

  return (
    <div>
      <h1>Count: {counter.count}</h1>
      <button onClick={() => setCounter((prev) => ({ count: prev.count + 1 }))}>
        Increment
      </button>
    </div>
  );
}

✅ No need to wrap your app in any provider — it just works.

🧩 Multiple Stores Example

Create multiple independent global stores easily.

// /store/user.ts
"use client";
import { createGlobalStore } from "@malahimdev/global-state";

interface UserState {
  name: string;
  loggedIn: boolean;
}

export const userStore = createGlobalStore<UserState>({
  name: "Guest",
  loggedIn: false,
});

Use it side-by-side:

"use client";
import { counterStore } from "@/store/counter";
import { userStore } from "@/store/user";

export default function HomePage() {
  const [counter, setCounter] = counterStore.useStore();
  const [user, setUser] = userStore.useStore();

  return (
    <div>
      <p>User: {user.name}</p>
      <p>Count: {counter.count}</p>
      <button onClick={() => setCounter((p) => ({ count: p.count + 1 }))}>
        Increment
      </button>
      <button
        onClick={() =>
          setUser(user.loggedIn ? { loggedIn: false, name: "Guest" } : { loggedIn: true, name: "Malahim" })
        }
      >
        {user.loggedIn ? "Logout" : "Login"}
      </button>
    </div>
  );
}

Access it in any component

"use client";
import Link from "next/link";
import { counterStore } from "@/store/counter";
import { userStore } from "@/store/user";

export default function OtherPage() {
  const [counter] = counterStore.useStore();
  const [user] = userStore.useStore();

  return (
    <div className="min-h-screen flex flex-col items-center justify-center bg-gradient-to-br from-pink-600 via-purple-600 to-indigo-600 text-white px-6">
      <div className="bg-white/10 p-6 sm:p-10 rounded-2xl text-center w-full max-w-md shadow-2xl">
        <h1 className="text-3xl sm:text-5xl font-extrabold mb-6 text-yellow-300">
          ⚡ Live Global State
        </h1>
        <p className="text-lg mb-4">👤 User: {user.name}</p>
        <p className="text-lg mb-6">🔥 Count: {counter.count}</p>
        <Link href="/" className="text-indigo-200 underline">
          ← Back to Home
        </Link>
      </div>
    </div>
  );
}

✅ Both pages stay perfectly synced — count and user changes reflect instantly!

📜 License

MIT © Malahim Haseeb (https://www.malahim.dev)