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

@buiducnhat/better-modal

v0.0.6

Published

A small, headless React utility for declarative modal state management. Register modals once, open them from anywhere in your app, and await their results as Promises.

Downloads

617

Readme

better-modal

A lightweight React library for declarative modal state management — open modals imperatively from anywhere in your app and await their results as Promises.

Stack: TypeScript · React 19 · Zustand 5 · Bun · Turborepo · Biome


Features

  • 🔌 Drop-in — place <ModalContainer /> once in your app root, done
  • Imperative API — call Modal.show(props) from anywhere, including outside React
  • 🤝 Promise-based resultsawait Modal.show() and get the user's response
  • 🎯 Selective re-renders — each modal subscribes only to its own Zustand slice
  • 🧩 Headless & UI-agnostic — works with any component library (MUI, shadcn, Radix, etc.)
  • 🔒 Type-safe — full TypeScript support for modal props

Prerequisites

  • Node.js 18+ or Bun 1.x
  • React 19+
  • Zustand 5+

Installation

# npm
npm install @buiducnhat/better-modal zustand

# bun
bun add @buiducnhat/better-modal zustand

Quick Start

1. Add <ModalContainer /> to your app root

import { ModalContainer } from "@buiducnhat/better-modal";

function App() {
  return (
    <>
      <YourRoutes />
      <ModalContainer />
    </>
  );
}

2. Create a modal

import { createModal } from "@buiducnhat/better-modal";

const ConfirmModal = createModal(
  "confirm",
  ({ modal, title }: { modal: any; title: string }) => (
    <dialog open={modal.visible}>
      <p>{title}</p>
      <button onClick={() => modal.resolve(true)}>Confirm</button>
      <button onClick={() => modal.resolve(false)}>Cancel</button>
    </dialog>
  ),
);

3. Open it from anywhere

// Inside or outside React components
const confirmed = await ConfirmModal.show({ title: "Delete this item?" });

if (confirmed) {
  deleteItem();
}

API Reference

createModal(id, Component)

Registers a modal component and returns a typed controller.

const Modal = createModal("my-modal", MyComponent);

Modal.show(props); // → Promise<result>
Modal.hide(); // close without resolving

useModal(id)

Hook to access modal state inside a modal component.

const modal = useModal("my-modal");

modal.visible; // boolean — is the modal open?
modal.props; // props passed to show()
modal.resolve(val); // close + resolve the Promise
modal.reject(err); // close + reject the Promise
modal.hide(); // close without resolving
modal.remove(); // remove from store entirely

<ModalContainer />

Place once at your app root. Renders all active modals.

registerModal(id, Component)

Low-level alternative to createModal — registers a component without returning the controller.


Documentation

| Doc | Description | | ----------------------------------------- | --------------------------------------- | | Project PDR | Product requirements and roadmap | | Architecture | System design and data flow | | Codebase Map | File structure and public API reference | | Code Standards | Conventions, naming, and tooling |


Development

# Install dependencies
bun install

# Type-check all packages
bun run check-types

# Lint and format
bun run check

# Build for publishing
bun run build

License

MIT