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

@realmjs/react-toast

v1.0.7

Published

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

10

Readme

React Toast

License: MIT

React Toast is a lightweight library that enables you to easily add toast notifications to your React applications. With React Toast, you can display informative messages, errors, or success notifications to enhance the user experience.

Note: React Toast ensures that only one toast notification is displayed on the screen at a time. If multiple toast notifications are triggered simultaneously, they will be placed in a queue and displayed one after another, maintaining a smooth and organized user experience.

Installation

npm install @realmjs/react-toast --save

Usage

To use React Toast in your React application, follow these steps:

  1. Import the necessary components and hooks:
import Toast, { useToast } from '@realmjs/react-toast';
  1. Set up the Toast Provider component in your application:
const App = () => {
  const toast = useToast();

  return (
    <div>
      <Toast.Provider toast={toast} />
      {/* Your application components */}
    </div>
  );
};
  1. Use the toast handler to show toast notifications, example below:
// show custom notification
toast.show((resolve, reject) => <CustomToast resolve={resolve} reject={reject}>Toast message</CustomToast>, { duration: 3000, bottom: true, animation: 'flyIn 0.8s' });
// show an error notification
toast.error('Error message', { closeButton: true, bottom: true });
//  show an info motification
toast.info('Info message', { duration: 3000, closeButton: false, animation: 'fadeIn' });
// show a success notification
toast.success('Success message', { duration: 3000, closeButton: false });

The toast.show function allows you to render a custom toast component with various options. The render parameter is a render function that returns the desired toast component. The options parameter can include:

  • duration: Sets the duration in milliseconds for how long the toast should be displayed.
  • bottom: If true, the toast will appear at the bottom of the screen.
  • animation: Configures the animation type and duration. Currently supports: flyIn, fadeIn, and zoomIn.

API

Toast.Provider

The Toast.Provider component is responsible for rendering and managing the toast notifications. It takes the following prop:

  • toast: The toast handler instance obtained using useToast.

useToast

The useToast hook provides access to the toast handler instance within functional components. It returns the toast handler object.

Toast Handler APIs

The toast handler object obtained from useToast provides the following APIs:

  • show(render, options): Displays a custom toast using the specified render function and options.
  • error(message, options): Displays an error toast with the given message and options.
  • info(message, options): Displays an informational toast with the given message and options.
  • success(message, options): Displays a success toast with the given message and options.

Please note that the show API allows you to provide a custom toast component through the render parameter, while the other APIs offer convenient shortcuts for displaying predefined toast types.

License

This project is licensed under the MIT License.