Skip to content

Commit 03419d4

Browse files
TheSharpieOnediegoddox
authored andcommitted
feat(getState): add ability to find state
Currently, this lib expects the state to be at the key `toastr` (and even handles when the state object is an immutable object (via `state.get`). There is no way to define a custom / different location easily. This adds an optional prop to the `ReduxToastr` component which is a function that takes the current state to provide the toastr state.
1 parent 6e84797 commit 03419d4

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import ReduxToastr from 'react-redux-toastr'
6666
newestOnTop={false}
6767
preventDuplicates
6868
position="top-left"
69+
getState={(state) => state.toastr} // This is the default
6970
transitionIn="fadeIn"
7071
transitionOut="fadeOut"
7172
progressBar

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-toastr",
3-
"version": "7.5.2",
3+
"version": "7.6.0",
44
"description": "react-redux-toastr is a React toastr message implemented with Redux",
55
"main": "lib/index.js",
66
"jsnext:main": "./src/index.js",

src/ReduxToastr.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ReduxToastr extends React.Component {
3434
transitionOut: TRANSITIONS.out[0],
3535
preventDuplicates: false,
3636
closeOnToastrClick: false,
37+
getState: (state) => state.toastr,
3738
confirmOptions: {
3839
okText: 'ok',
3940
cancelText: 'cancel'
@@ -155,8 +156,8 @@ export class ReduxToastr extends React.Component {
155156
}
156157

157158
export default connect(
158-
state => ({
159-
toastr: state.toastr ? state.toastr : state.get('toastr')
159+
(state, ownProps) => ({
160+
toastr: ownProps.getState(state),
160161
}),
161162
actions
162163
)(ReduxToastr);

0 commit comments

Comments
 (0)