Change snackbar to fix issue where lingering timeouts would effect new activations
parent
36e3a86c2e
commit
6470b44d5a
|
@ -18,11 +18,24 @@ class Snackbar extends React.Component {
|
|||
type: React.PropTypes.string
|
||||
};
|
||||
|
||||
componentDidUpdate () {
|
||||
if (this.props.active && this.props.timeout) {
|
||||
setTimeout(() => {
|
||||
this.props.onTimeout();
|
||||
}, this.props.timeout);
|
||||
state = {
|
||||
curTimeout: null
|
||||
};
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (nextProps.active && nextProps.timeout) {
|
||||
if(this.state.curTimeout) clearTimeout(this.state.curTimeout);
|
||||
|
||||
let curTimeout = setTimeout(() => {
|
||||
nextProps.onTimeout();
|
||||
this.setState({
|
||||
curTimeout: null
|
||||
});
|
||||
}, nextProps.timeout);
|
||||
|
||||
this.setState({
|
||||
curTimeout
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue