Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

toastify-react

hannadrehman545MIT4.3.1TypeScript support: included

Beautiful, Zero Configuration, Toast Messages - Built with React forked from cogo-toast

react, toast, react-toast, toast-react, toastr, toast messages, messages, notifications, react notifications, component, components, react component, react components, ui

readme

toastify-react

Toastify React

Beautiful, Zero Configuration, Toast Messages for React ~3kb gzip (with styles and icons)

https://hannadrehman.github.io/toastify-react/

npm package Small size npm Code style GitHub license

Toastify React

Install via NPM:

npm install --save toastify-react

Install via Yarn:

yarn add toastify-react

Usage

Its Plug and Play. No configuration required. Just import and you are good to go.

import toaster from 'toastify-react';

toaster.success('This is a success message!');

5 Built in Types

There are 5 built-in types to handle the most common cases in any application.

toaster.success('This is a success message');

toaster.info('This is a info message');

toaster.loading('This is a loading message');

toaster.warn('This is a warn message');

toaster.error('This is a error message');

Use JSX

toastify-react is built using React. Which means any valid jsx can be used as the message in toaster

toaster.info(
  <div>
    <b>Awesome!</b>
    <div>Isn't it?</div>
  </div>,
);

Returns a Promise

Returns a promise which resolves when the toast is about to hide.

This can be useful to do some action when the toast has completed showing.

toaster.loading('Loading your data...').then(() => {
  toaster.success('Data Successfully Loaded');
});

Hide on Click

const { hide } = toaster.success('This is a success message.', {
  onClick: () => {
    hide();
  },
});

Completely Customizable

The second parameter to the function is an options object that can be passed in for customization.

toaster.info('This is an info message', options);

All Available Options

Here's a list of all the available options, to customize the toast to your needs.

Options Type Default
hideAfter Number in Seconds 3
(Can be 0 to disable auto-hiding of the toast)
position 'top-left', 'top-center', 'top-right',
'bottom-left', 'bottom-center', 'bottom-right'
'top-center'
heading String ''
renderIcon Function<ReactNode> Icon Based on the Type
bar Object
{ size: '2px', style: 'solid/dashed/dotted', color: '#hex' }
Based on the Type
onClick() Function null
role aria-role status
toastContainerID The dom element in which the toast container is added ct-container

Custom Styling

You can provide your own custom styling by extending the ct-toast class in your css styles.

For all classnames, refer to /src/styles/styles.css

Customize each type of Toast seperately

Customize each type of Toast seperately, by extending the ct-toast-<type> class. For example, in your CSS,

ct-toast-success {
  color: #FFFFFF;
  background: #6EC05F;
}

Only ~ 3kb gzip (with Styles and Icons)

The package contains the minified build file, along with the SVG Icons and the Styles, built into the Code, with a total of only ~3kb gzip.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Anmol Mahatpurkar

💻 🎨 📖

Balázs Orbán

💻

Vitalii Kalchuk

💻

Amar Pathak

📖

Nataly Shrits

💻

hannad rehman

💻

Kartik Hedau

💻 🖋 🎨 📖 💡

This project follows the all-contributors specification. Contributions of any kind welcome!

How to run locally

yarn setup
yarn dev // runs rullup in watch mode
yarn dev:docs // runs docs website in dev mode.

changelog

Features

  • 4.2.3

    • Fix: install error at 4.2.2. #53
  • 4.2.2

    • Fix: useEffect not cancelling timeouts. #49
    • Switched from pnpm to yarn to manage package dependencies - Better community support.
  • 4.2.1

    • Fix: Heading and renderIcon not being passed to the toast component
  • 4.2.0

    • Refactored entire codebase to TypeScript.
    • Switched from yarn to pnpm to manage package dependencies.
    • Bundle Size reduced to 4 KB
    • No change to the package API or features. Everything should work as before.
  • 4.2.0-beta.0

    • Refactored entire codebase to TypeScript.
    • Switched from yarn to pnpm to manage package dependencies.
    • Bundle Size reduced to 4 KB
    • No change to the package API or features. Everything should work as before.
  • 4.1.3

    • Fixes #44 and #45
  • 4.1.1

    • Added missing types for 4.0, role, and toastContainerID. #35
  • 4.1.0

    • Added a new option toastContainerID. This enables specifying the id of the parent dom element, to which the toast is mounted as a child. #27
  • 4.0.0

    • Breaking Change

      • Hide the toast on Click

      Before:

        cogoToast.success('This is a success message.', {
          onClick: (hide) => {
            hide();
          },
        };

      Now:

        const { hide } = cogoToast.success('This is a success message.', {
          onClick: () => {
            hide();
          },
        };
      • Toast now always returns a promise, as opposed to before. See issue #28

      • Accesibilty - Added a role of status by default. Configurable via options. Thanks @balazsorban44.

  • v3.2.2

    • classnames added to each type of toast, to enable css overrides
  • v3.2.1

    • 3.2.0 Accidentally published a Non-Minified Build. 3.2.1 fixes this
  • v3.2.0

    • JSX Support:

      • Prop types fix when using React node instead of a text message.
      • JSX Usage added in the documentation.
  • v3.1.0

    • Ability to hide the toast immediately on click. hide function passed as a param in onClick.
    cogoToast.success('This is a success message.', {
        onClick: (hide) => {
            hide();
        },
    });
  • v3.0.0

    • Major internal rewrite to remove ReactDOMServer dependency.

    • Using react hooks internally, so support for React versions before hooks is now dropped. Use v2.0.1 if you want to use this library in versions before React@16.8 (pre-hooks)

    Breaking:

    • icon option changed to renderIcon, where you can pass a render function instead of a node. (Useful for Lazy Rendering)
    • Export for create function removed. cogoToast() works like create did before.
  • v2.0.1

    • Fix for top level typings declaration
  • v2.0.0

    • Custom styling is now supported. Just extend the css classes to specify your own styles. For all classnames, refer to /src/styles.css

    • Typescript typings added. Shout out to @sebastien-p

  • v1.0.7 - Internal dependencies and build system upgraded. No changes to the toast.

  • cogoToast: cogoToast is the root object of the containing of 5 functions, success, info, loading, warn, and error.