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

promise-render

v0.1.2

Published

Render React components as async functions — _await user interaction_ just like fetching data.

Readme

promise-render

Render React components as async functions — await user interaction just like fetching data.

promise-render is a tiny utility that lets you render a React component imperatively and wait for its result via a Promise. Perfect for confirmation dialogs, pickers, wizards, forms, and any UI that needs to “return a value” to your async code.

🚀 Features

  • Render any React component and get its output via a Promise
  • Call UI from thunks, sagas, services, or any async function
  • No context, no event bus, no global stores
  • Component automatically unmounts after resolve/reject
  • TypeScript support included

📦 Installation

npm install promise-render
# or
yarn add promise-render

🧠 Core Concept

promiseRender(Component) returns a pair:

const [ asyncFunction, AsyncComponent ] = promiseRender(Component)
  • AsyncComponent is a React component you render once (e.g. in a modal root).
  • asyncFunction(props?) renders that component and returns a Promise.
  • Inside the component, two special props are available:
  • resolve(value) — resolves the promise & unmounts the component
  • reject(error) — rejects the promise & unmounts the component

This allows you to control UI flow like this:

const result = await asyncFunction(props);

🏎️ Quick Example

import { promiseRender } from 'promise-render';

const ConfirmDelete = ({ resolve }) => (
  <Modal>
    <p>Delete user?</p>
    <button onClick={() => resolve(true)}>Yes</button>
    <button onClick={() => resolve(false)}>No</button>
  </Modal>
);

const [confirmDelete, ConfirmDeleteAsync] = promiseRender<boolean>(ConfirmDelete);

// Render the async component once in your root:
function App() {
  return (
    <>
      <MainApp />
      <ConfirmDeleteAsync />
    </>
  );
}

// Now you can await UI from anywhere:
async function onDeleteClick() {
  const confirmed = await confirmDelete();
  if (!confirmed) return;

  await api.deleteUser();
}
  • ✅ No global event emitters.
  • ✅ No prop drilling.
  • ✅ Just await your UI.

🎛️ Passing Props

You can pass any props to the async function. They will be forwarded to the component automatically.

import { promiseRender } from 'promise-render';

const ConfirmAlert = ({ resolve, text }) => (
  <Modal>
    <p>{text}</p>
    <button onClick={() => resolve(true)}>Yes</button>
    <button onClick={() => resolve(false)}>No</button>
  </Modal>
);

const [confirm, ConfirmAlertAsync] = promiseRender<boolean>(ConfirmAlert);

// Render <ConfirmAlertAsync /> somewhere in your root

const deleteUser = createAsyncThunk('deleteUser', async () => {
  const confirmed = await confirm({
    text: "Are you sure you want to delete this user?",
  });

  if (!confirmed) return;

  await api.deleteUser();
});

🧰 Common Use Cases

  • ✅ Confirmation dialogs
  • ✅ Pickers / Select modals
  • ✅ Login or consent popups
  • ✅ Form dialogs that “return” values
  • ✅ Wizards or multi-step flows
  • ✅ Any async interaction that should “pause” logic until user acts

If you ever wished JavaScript had await confirmDialog() — now it does.

🧪 Advanced Example: Returning Form Data

const NamePrompt = ({ resolve }) => {
  const [name, setName] = useState("");

  return (
    <Modal>
      <input value={name} onChange={e => setName(e.target.value)} />
      <button onClick={() => resolve(name)}>Submit</button>
    </Modal>
  );
};

const [promptName, NamePromptAsync] = promiseRender<string>(NamePrompt);

async function createItem() {
  const name = await promptName();
  await api.createItem({ name });
}

🧹 Cleanup & Unmounting

promise-render handles lifecycle automatically:

  • Component mounts when the async function is called
  • Component unmounts when resolve or reject is triggered
  • The same mounted component instance is reused between calls

No global state or manual cleanup required.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Feel free to extend or modify this README according to your preferences!