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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-alert-messages

v1.0.22

Published

This is a react alert messages helper context

Downloads

213

Readme

react-alert-messages

Features

  • Alert messages disappear after fixed time
  • Option to configure the alert display time
  • Support to show alerts indefinitely
  • Option to remove an alert with alert ID
  • Option to update existing alert details
  • Support multiple pending message with same key and hold the pending message until all get success or failed messages

How to use

  • First, install the package using npm or yarn:

    npm install react-alert-messages

    or

    yarn add react-alert-messages
  • Import the AlertMessagesContext, AlertMessagesProvider and the useContext hook from react in your component: jsx

    import React, { useContext } from 'react';
    import AlertMessagesProvider, { AlertMessagesContext } from 'react-alert-messages';
  • Wrap your root component with the AlertMessagesProvider component, and pass in any necessary options as props: jsx

    function App() {
      return (
        <AlertMessagesProvider position="top-right" timeout={5000}>
        {/* The rest of your application */}
        </AlertMessagesProvider>
      );
    }
  • Call the useContext hook to get a reference to the AlertMessagesContext and the postAlertMessage function: jsx

    const { postAlertMessage } = useContext(AlertMessagesContext);

    In this example, we are passing in the text property to the postAlertMessage function. Details of the other properties are provided below in the config details section.

  • Use the postAlertMessage function to post an alert message in response to a user action, such as a button click: jsx

    const handleClick = () => {
    postAlertMessage({ text: 'This is a test message' });
    };
      
    return (
      <div>
        {/* The rest of your component */}
        <button onClick={handleClick}>Post message</button>
      </div>
    );

    And that's it! With these steps, you should be able to use react-alert-messages to post customizable alert messages in response to user actions using the AlertMessagesContext and the postAlertMessage function.

Special Use cases

Progress and success/error alert

Can post an indefinite info type alert with loading message with a unique key. After completing the action, the same alert message can be updated to success or error message based on the action's outcome with a fixed timeout.

Multiple progress and one success or failure

Can post multiple pending alert messages and send success and failure updates for each. The alert message handler will hold the progress message until received all success/failure message corresponding to each pending and will show the success/failure based on the update messages.

Config Details

Alert message types

  • success
  • error
  • in-progress

Alert message timeout

The timeout prop specifies how long the alert messages should be displayed before automatically disappearing. Timeout should be passed in milliseconds. This will be defaulted with 2000 if not passed. This will support -1 as value to display the message indefinitely.

How it works

  1. AlertMessagesProvider component in AlertMessagesContext.tsx is wrapped with context provider as well as associated function to allow the alert message functionality
  2. Child component is wrapped with AlertMessagesProvider to allow the deliver of context.