React Redux Toastr

8.0.0 · maintenance · verified Tue Apr 21

react-redux-toastr provides a robust toastr-style notification system for React applications, deeply integrating with Redux for state management. The current stable version is 8.0.0, published approximately two years ago, indicating a maintenance phase rather than active, rapid development. While the 7.x series saw several minor updates, the jump to v8 brought no explicit breaking changes documented in its changelog for the library's core API, focusing on compatibility and stability. This library differentiates itself by managing all toast notification states within the Redux store, ensuring a centralized and predictable approach. It offers extensive customization for notification positioning, animation transitions, and progress indicators, and uses an event emitter pattern for triggering toasts from any part of the application. It requires explicit Redux reducer integration and a root-level component for rendering notifications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `react-redux-toastr` by adding its reducer to the Redux store, rendering the `ReduxToastr` component at the application root, and triggering various toast messages (success, info, error, confirm) using the `toastr` emitter.

import React from 'react';
import ReactDOM from 'react-dom/client';
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import ReduxToastr, { reducer as toastrReducer, toastr } from 'react-redux-toastr';

// Import CSS styles (mandatory)
import 'react-redux-toastr/lib/css/react-redux-toastr.min.css';

// 1. Add the reducer to your Redux store
const rootReducer = combineReducers({
  // ... other reducers ...
  toastr: toastrReducer // <- Mounted at 'toastr' by default
});

const store = createStore(rootReducer);

// 2. Create a component to trigger toasts
const MyAppComponent = () => {
  return (
    <div>
      <h1>Welcome to React Redux Toastr Demo</h1>
      <button onClick={() => toastr.success('Success!', 'This is a success message.')}>
        Show Success Toast
      </button>
      <button onClick={() => toastr.info('Info', 'This is an information message.')}>
        Show Info Toast
      </button>
      <button onClick={() => toastr.error('Error', 'Something went wrong!', { timeOut: 0 })}>
        Show Error Toast (no timeout)
      </button>
      <button onClick={() => toastr.confirm('Are you sure?', {
        onOk: () => console.log('Confirmed'),
        onCancel: () => console.log('Cancelled')
      })}>
        Show Confirm Toast
      </button>
    </div>
  );
};

// 3. Render the ReduxToastr component at your app root
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Provider store={store}>
    <MyAppComponent />
    <ReduxToastr
      timeOut={4000}
      newestOnTop={false}
      preventDuplicates
      position="top-right"
      getState={(state) => state.toastr} // Default, can be customized
      transitionIn="fadeIn"
      transitionOut="fadeOut"
      progressBar
      closeOnToastrClick
    />
  </Provider>
);

view raw JSON →