when a new message is set, clear previous timeout

This commit is contained in:
Danny van Kooten 2017-01-13 13:41:30 +01:00
parent b5b31d89f8
commit f6cab7c297
1 changed files with 3 additions and 1 deletions

View File

@ -10,6 +10,7 @@ class Notification extends Component {
message: props.message,
kind: props.kind || 'error'
}
this.timeout = 0
}
clearMessage() {
@ -19,7 +20,8 @@ class Notification extends Component {
componentWillReceiveProps(newProps) {
if(newProps.message != this.state.message) {
this.setState({ message: newProps.message, kind: newProps.kind || 'error' })
window.setTimeout(this.clearMessage.bind(this), 5000)
window.clearTimeout(this.timeout)
this.timeout = window.setTimeout(this.clearMessage.bind(this), 5000)
}
}