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-styled-alert

v1.0.7

Published

Styled alerts that don't lock the browser

Downloads

17

Readme

react-styled-alert

react-styled-alert allows you to use react components in place of the usual alert popup, allowing you to style them however you want as well as execute code.

Installation

$ npm install --save react-styled-alert

Example

// Your app
import { AlertProvider } from 'react-styled-alert';

export function App() {
  return(
    <AlertProvide>
      <Page />
      <Alert />
    </AlertProvider>
  );
}

// Your page
import { useAlert } from 'react-styled-alert';

export function Page() {
  const styledAlert = useAlert();
  return (
    <button onClick={() => styledAlert('Alert message!')}>
      Click me
    </button>
  );
}

// Your alert component
import { useAlertData } from 'react-styled-alert';

export function Alert() {
  const alert = useAlertData();
  if (alert) {
    return (
      <div>
        {alert.content}
        <button onClick={alert.onOk}>
          Ok
        </button>
      </div>
    );
  } else {
    return (
      <></>
    );
  }
}

Documentation

This package comes with two hooks, useAlert and useAlertData. The first gives you a function to replace JavaScript's alert. You call it sending your message and two optional functions onOk and onCancel, meant to be called when the user clicks ok or cancel on the alert popup. The useAlertData hook gives you access to the data you sent with useAlert. The component is a provider, and the hooks only work when called from within it.

Internally, each call of the useAlert returned function fills an array with the data you sent so you can queue each alert, and the useAlertData hook returns the most recent one. Whenever you execute either onOk or onCancel, you will also remove their alert entry from this array.

AlertProvider component

The other hooks only work when called on components rendered inside this provider.

<AlertProvider>
  your app here
</AlertProvider>

useAlert hook

This hook returns a function for you to use instead of JavaScript's alert. Only works inside AlertProvider.

const styledAlert = useAlert();
styledAlert(
  content,
  onOk,        // Optional function to call when the user clicks ok
  onCancel     // Optional function to call when the user clicks cancel
);

It accepts three arguments:

  • content A ReactNode to be the message displayed in your alert component. Can be the usual string but you can do anything with it, really.
  • onOk Optional. A function to be called when the user clicks ok, supposing your alert component has an Ok button.
  • onCancel Optional. A function to be called when the user clicks cancel, supposing your alert component has a Cancel button.

useAlertData hook

To be used to create your alert component. This hook returns an object with the content, onOk and onCancel values passed to it by the useAlert hook, or null when no alert has been called yet. If no onOk was passed, () => {return} is received, and if no onCancel was passed, null is received. Don't forget that calling either removes their entire alert data from the queue. Only works inside AlertProvider.

const alert = useAlertData();
console.log(alert);
// { content, onOk, onCancel } or null

Demo

Here is a codesandbox demo with some code and how it looks.

Credits

By Rafael de Lima Bordoni.

License

Licensed under MIT.