Skip to content

Commit

Permalink
Pass correct callbacks to snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Feb 23, 2020
1 parent e799616 commit f9cb22a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/SnackbarItem/SnackbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ class SnackbarItem extends Component {
}, 125);
}

get unusedCallbacks() {
return ['onEnter', 'onEntering', 'onExit', 'onExiting'].reduce((acc, cbName) => ({
...acc,
[cbName]: (...args) => {
const { snack } = this.props;
if (typeof snack[cbName] === 'function') {
snack[cbName](...args, snack.key);
}
if (typeof this.props[cbName] === 'function') {
this.props[cbName](...args, snack.key);
}
},
}), {});
}

render() {
const {
classes,
Expand Down Expand Up @@ -136,6 +151,7 @@ class SnackbarItem extends Component {
classes={getSnackbarClasses(classes)}
onClose={this.handleClose(key)}
onEntered={this.handleEntered(key)}
{...this.unusedCallbacks}
>
{snackContent || (
<SnackbarContent
Expand Down

0 comments on commit f9cb22a

Please sign in to comment.