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

react-modal-orchestrator

v1.0.5

Published

A centralized and flexible modal management system for React applications.

Readme

react-modal-orchestrator

A centralized and flexible modal management system for React applications, now with lazy loading!

react-modal-orchestrator provides a clean, decoupled architecture for managing modals. Instead of controlling modal state with useState in every component, you can register all your modals in one place and trigger them from anywhere in your application.

Additionally, by using React.lazy when registering your modals in your modal dictionary, modal components are only loaded when they are first opened, reducing your application's initial bundle size.

Core Concepts

  • ModalOrchestrator: A provider component that wraps your application and powers the entire modal system.
  • ModalHandler: A component that listens for active modals and renders them. It now includes React.Suspense to handle lazy-loaded components.
  • Modal Dictionary: A simple JavaScript object where you map a unique name to each dynamically imported modal component.
  • useContext for Control: Use React's useContext hook to access the openModal and closeModal functions from anywhere in your component tree.

Installation

npm install react-modal-orchestrator

Setup

First, you need to wrap your application with the ModalOrchestrator and place the ModalHandler within it.

1. Create a Lazy-Loaded Modal Dictionary

To take advantage of code-splitting, define your modal dictionary using React.lazy. This tells React to load the component code only when it's first rendered.

Create a file (e.g., modals.ts) to define and register your modals.

// components/MyFirstModal.tsx
import React, { useContext } from "react";
import {ModalDispatchContext} from "react-modal-orchestrator";

// Note: The component must be a default export for React.lazy to work
export const MyFirstModal = ({ title }) => {
  const { closeModal } = useContext(ModalContext);
  return (
    <div>
      <h2>{title}</h2>
      <p>This is my first modal!</p>
      <button onClick={closeModal}>Close</button>
    </div>
  );
};
export default MyFirstModal;


// modals.ts
import React from "react";

export const modalDictionary = {
  MY_FIRST_MODAL: React.lazy(() => import("./components/MyFirstModal")),
  // ... register other lazy-loaded modals here
};

2. Wrap Your App

In your main application file (e.g., App.tsx), import the ModalOrchestrator, ModalHandler, and your modal dictionary.

// App.tsx
import { ModalOrchestrator, ModalHandler } from "react-modal-orchestrator";
import { modalDictionary } from "./modals";

function App() {
  return (
    <ModalOrchestrator modals={modalDictionary}>
      {/* Your application components */}
      <h1>My App</h1>
      <TriggerButton />

      {/* 
        Place the handler at the top level.
        You can customize the loading fallback in your own Suspense boundary.
      */}
      <ModalHandler />
    </ModalOrchestrator>
  );
}

Usage

Opening a Modal

No more passing state around to conditionally render modals.

If your modal manages its open state, simply set its isOpen to true.

To open a modal, import ModalDispatchContext, get the openModal function from the context, and call it with the registered name of the modal you want to open.

If your modal needs props, just pass an object of props as the 2nd argument to openModal.

// components/TriggerButton.tsx
import React, { useContext } from "react";
import {ModalDispatchContext} from "react-modal-orchestrator";

const TriggerButton = () => {
  const { openModal } = useContext(ModalContext);

  const handleClick = () => {
    // Open the modal and pass props to it
    openModal("MY_FIRST_MODAL", { title: "Hello World!" });
  };

  return <button onClick={handleClick}>Open Modal</button>;
};

Closing a Modal

The ModalDispatchContext also provides a closeModal function to your modal component via context. Use the useContext hook to access it.

// components/MyFirstModal.tsx
import React, { useContext } from "react";
import {ModalDispatchContext} from "react-modal-orchestrator";

// Ensure the component is a default export
const MyFirstModal = ({ title }) => {
  const { closeModal } = useContext(ModalContext); // Get closeModal from context

  return (
    <div>
      <h2>{title}</h2>
      <button onClick={closeModal}>Close Me</button>
    </div>
  );
};

export default MyFirstModal;

License

This project is licensed under the ISC License.