##react-redux-toastr
This is a fork of http://diegoddox.github.io/react-redux-toastr/
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.
npm install --save inspera/react-redux-toastr
Import or copy the less file into to your project.
import 'react-redux-toastr/src/less/index.less'
import {createStore, combineReducers} from 'redux'
import {reducer as toastrReducer} from 'react-redux-toastr'
const reducers = {
// ... other reducers ...
toastr: toastrReducer // <- Mounted at toastr.
}
const reducer = combineReducers(reducers)
const store = createStore(reducer)
import {Provider} from 'react-redux'
import ReduxToastr from 'react-redux-toastr'
<Provider store={store}>
<div>
... other things like router ...
// props are not required
<ReduxToastr
timeOut={4000}
newestOnTop={false}
position="top-left"/>
</div>
</Provider>
default props: In case you don't pass the props
timeOut: null,
newestOnTop: true,
position: 'top-right'
positions: top-left
top-right
bottom-left
bottom-right
top-fw
The toastr
method use eventemitter3 to dispatch the actions
import React, {Component} from 'react'
import {toastr} from 'react-redux-toastr'
export class YourComponent extends Component {
render() {
return (
<div>
<button
onClick={() => toastr.success('The title', 'The message')}
type="button">Toastr Success</button>
</div>
)
}
}
Or you can bind the actions
to your component if you prefer.
import {bindActionCreators} from 'redux'
import {actions as toastrActions} from 'react-redux-toastr'
// In your React component
constructor(props) {
super(props);
// Bind the react-redux-toastr actions to the component
this.toastr = bindActionCreators(toastrActions, this.props.dispatch)
}
Each of these methods can take up to three arguments the title
a message
and options
.
In options
you can specify the timeout
onShowComplete
onHideComplete
and component
.
The component
must be a React component. It will receive the title, message and options object as props.
import {toastr} from 'react-redux-toastr'
const toastrOptions = {
timeOut: 3000,
onShowComplete: () => console.log('SHOW: animation is done'),
onHideComplete: () => console.log('HIDE: animation is done'),
component: React.Component
}
toastr.success('Title', 'Message', toastrOptions)
toastr.info('Only a title', toastrOptions)
toastr.info(null, 'Only a message', toastrOptions)
toastr.warning('The title', 'The message')
toastr.error(toastrOptions)
git clone https://github.com/inspera/react-redux-toastr.git
cd react-redux-toastr
npm install
npm start
open your browser at http://localhost:3000