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-confirm-action

v0.1.0

Published

Headless inline confirmation for async React actions

Downloads

138

Readme

react-confirm-action

Inline confirmation for React actions.

Instead of opening a modal before a destructive action, the button asks the user to click again before the action runs.

<ConfirmButton action={deleteProject}>
  Delete project
</ConfirmButton>

Flow:

Delete project
→ Click again to confirm
→ Pending...
→ Delete project

If the second click does not happen before the timeout, the button returns to its initial state.

Installation

npm install react-confirm-action

ConfirmButton

The quickest way to use the package:

import { ConfirmButton } from "react-confirm-action";

function DeleteProjectButton() {
  const deleteProject = async () => {
    await fetch("/api/project", {
      method: "DELETE",
    });
  };

  return (
    <ConfirmButton
      action={deleteProject}
      confirmText="Click again to delete"
      pendingText="Deleting..."
      errorText="Try again"
      timeout={3000}
    >
      Delete project
    </ConfirmButton>
  );
}

Props

action

Function that runs after the second click.

action: () => void | Promise<void>

timeout

Time in milliseconds during which the second click is accepted.

Default:

3000

confirmText

Content shown after the first click.

Default:

Click again to confirm

pendingText

Content shown while the action is running.

Default:

Pending...

errorText

Content shown when the action throws or returns a rejected Promise.

Default:

Try again

ConfirmButton also accepts standard HTML button props such as:

<ConfirmButton
  action={deleteProject}
  className="danger"
  type="button"
  aria-label="Delete project"
>
  Delete
</ConfirmButton>

The button is automatically disabled while the action is pending.

useConfirmAction

For full control over the UI, use the headless hook directly.

import { useConfirmAction } from "react-confirm-action";

function DeleteProjectButton() {
  const { state, error, trigger, reset } = useConfirmAction({
    action: async () => {
      await fetch("/api/project", {
        method: "DELETE",
      });
    },
    timeout: 3000,
  });

  return (
    <>
      <button
        onClick={() => void trigger()}
        disabled={state === "pending"}
      >
        {state === "idle" && "Delete project"}
        {state === "confirming" && "Click again to delete"}
        {state === "pending" && "Deleting..."}
        {state === "error" && "Try again"}
      </button>

      {error instanceof Error && (
        <p>{error.message}</p>
      )}

      {state !== "idle" && (
        <button onClick={reset}>
          Reset
        </button>
      )}
    </>
  );
}

States

useConfirmAction exposes four states:

type ConfirmActionState =
  | "idle"
  | "confirming"
  | "pending"
  | "error";

Flow:

idle
  ↓ first trigger

confirming
  ↓ second trigger

pending
  ↓ success        ↓ failure

idle               error

If the confirmation timeout expires:

confirming
→ idle

Calling trigger() while the action is already pending does not run the action again.

Why inline confirmation?

Confirmation dialogs are useful when an action needs additional context or a strong interruption.

For smaller destructive actions, a modal can be unnecessarily disruptive.

Inline confirmation keeps the interaction in place:

Delete
→ Click again to delete

Typical use cases include:

  • deleting an item;
  • disconnecting an integration;
  • revoking an API key;
  • resetting settings;
  • removing a member;
  • cancelling an operation.

Headless by default

The core useConfirmAction hook does not provide styles or layout.

You control:

  • button styles;
  • icons;
  • animations;
  • labels;
  • error rendering;
  • surrounding UI.

The package manages:

  • confirmation state;
  • confirmation timeout;
  • async action lifecycle;
  • pending state;
  • errors;
  • protection from repeated execution.

Requirements

  • React 18 or newer
  • React DOM 18 or newer

License

MIT