Last active
July 17, 2018 18:16
-
-
Save a-x-/634684f6112d5b69c6c8a0b423752972 to your computer and use it in GitHub Desktop.
react temporal state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Временное выставление статуса | |
class Foo extends React.PureComponent { | |
// ... | |
foo () { | |
// ... | |
this.setState({ | |
triggered: setTimeout(() => this.setState({ triggered: null }), 500) | |
}) | |
} | |
componentWillUnmount () { | |
if (this.state.triggered) clearTimeout(this.state.triggered) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment