Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-redux-toastr

> 前端框架
Open source

react-redux-toastr is a toastr message implemented with Redux

748 stars0 likes2 views
WebsiteGitHub

About

react-redux-toastr is a toastr message implemented with Redux

react-redux-toastr demo

react-redux-toastr is a React toastr message implemented with Redux, primary consists of three things: a reducer, toastr emitter and a React component.

The reducer listens to dispatched actions from the component to maintain the toastr state in Redux.

Implementation Guide

1. Installation

npm install --save react-redux-toastr

2. Add the styles
  • import the scss file into to your project.

    @import 'react-redux-toastr/src/styles/index';
    
  • or import the css file.

import 'react-redux-toastr/lib/css/react-redux-toastr.min.css'
  • or include the css file from the demo site (NOTE: This file can be changed anytime)
3. Add the reducer.
import {createStore, combineReducers} from 'redux'
import {reducer as toastrReducer} from 'react-redux-toastr'
const reducers = {
  // ... other reducers ...
  toastr: toastrReducer //  {}, //override default behavior of 'attention' background click.
   message: 'message',
   options: {}
  });

  this.toastr.remove('toastrId');
}

Toastr methods

Toastr accepts the following methods: success info warning light error confirm message, remove and removeByType

Toastr: success info warning light error remove and removeByType

Each of these methods can take up to three arguments the title a message and options.

In options you can specify timeOut icon onShowComplete onHideComplete className component removeOnHover,removeOnHoverTimeOut,showCloseButton, onCloseButtonClick, onToastrClick, progressBar, transitionIn, position, attention, onAttentionClick, transitionOut and closeOnToastrClick.

…
Toastr methods light

The light method is like the other toastr except that the background-color is white and you can add a top border on top of the toastr by passing the status option

icon can be one of the following:

  • 'success'
  • 'info'
  • 'warning'
  • 'error'
import {toastr} from 'react-redux-toastr'

const toastrType = 'warning';
const toastrOptions = {
  icon: toastrType,
  status: toastrType
}

toastr.light('The title', 'The message', toastrOptions)
Toastr: message

Use this one if you wanna show a large amount of information. Unlike the other methods above, it would not close automatically unless you provide a timeout in the message options.

const toastrMessageOptions = {
  timeOut: 3000, // Default value is 0
  onShowComplete: () => console.log('SHOW: animation is done'),
  onHideComplete: () => console.log('HIDE: animation is done'),
  removeOnHover: false, // Default value is false
  removeOnHoverTimeOut: 1000, // Default value is 1000
  component: React.Component
};
toastr.message('Title', toastrMessageOptions)
Toastr: confirm

The confirm method takes two arguments. The first one is the message and the second one is an object where you can specify what will happen when the user clicks on ok or on the cancel buttons or on keypress enter/esc.

NOTE: You can only have one confirm toastr at the same time. If you have one confirm and you fire another it will be ignored.

const toastrConfirmOptions = {
  onOk: () => console.log('OK: clicked'),
  onCancel: () => console.log('CANCEL: clicked')
};
toastr.confirm('Are you sure about that!', toastrConfirmOptions);

You can add a manually specified CSS ID selector to the confirmation wrapper element by:

  • Including an id prop in the toasterConfirmOptions object:
const toastrConfirmOptions = {
  ...
  id: 'my-custom-id'
};
toastr.confirm('Are you sure about that!', toastrConfirmOptions);

You can change the ok and cancel texts by:

  • Passing confirmOptions to the ReduxToastr component:

const options = {
  okText: 'confirm text',
  cancelText: 'cancel text'
};
  • Passing okText and cancelText in the toasterConfirmOptions object:
const toastrConfirmOptions = {
  ...
  okText: 'confirm text',
  cancelText: 'cancel text'
};

toastr.confirm('Are you sure about that!', toastrConfirmOptions);

You can make it so ok is the only button by:

  • Passing disableCancel in the toasterConfirmOptions object:
const toastrConfirmOptions = {
  ...
  disableCancel: true
};

toastr.confirm('You have timed out! Please log back in.', toastrConfirmOptions);

You can add custom buttons by:

  • Passing buttons in the toasterConfirmOptions object.

    The buttons are inserted after the OK and the cancel buttons.

    Each button config can have a text, handler and a className property.

    If you want to move the original OK or cancel buttons to a different postiion, just insert a an object with a single boolean flag: ok or cancel to the desired position inside buttons. (note that all other properties are ignored in this case).

The following config leads to 3 buttons in the following order:

  1. "Apply" (original OK button)
  2. "Do not apply" (our custom button)
  3. "Cancel" (original cancel button)
const toastrConfirmOptions = {
  ...
  okText: 'Apply',
  buttons: [{
    text: 'Do not apply',
    className: 'do-not-apply-btn',
    handler: () => console.log('do-not-apply clicked')
  }, {
    cancel: true // move the cancel button to the end
  }]
};

toastr.confirm('Your changes are applicable to 5 more records.', toastrConfirmOptions);

You can render your custom message component instead of the simple string message by:

  • Passing the component prop to the toasterConfirmOptions object:
const toastrConfirmOptions = {
  ...
  component: () => (
    
      Hello, World!
    
  )
};

toastr.confirm(null, toastrConfirmOptions); // pass null for message

You can allow user to close confirm dialog by clicking in empty space

  • Passing closeOnShadowClick in the toasterConfirmOptions object:
const toastrConfirmOptions = {
  ...
  closeOnShadowClick: true
};

toastr.confirm('You have timed out! Please log back in.', toastrConfirmOptions);

Avatar: in case you wanna use the same avatar as in the example

Avatar

Run a local demo

git clone https://github.com/diegoddox/react-redux-toastr.git
cd react-redux-toastr
npm install
npm start

open your browser at http://localhost:3000

License

MIT. Copyright (c) 2016 Diego Oliveira.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptreactreduxtoastr

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架