Change snackbar to fix issue where lingering timeouts would effect new activations

old
James Hycner 2016-03-27 16:29:08 -07:00
parent 36e3a86c2e
commit 6470b44d5a
1 changed files with 18 additions and 5 deletions

View File

@ -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
});
}
}