Skip to content

Instantly share code, notes, and snippets.

@vldvel
Last active October 10, 2020 16:54
Show Gist options
  • Save vldvel/d37796e99a7f300dfe22b0f94370e533 to your computer and use it in GitHub Desktop.
Save vldvel/d37796e99a7f300dfe22b0f94370e533 to your computer and use it in GitHub Desktop.
setInterval in componentdidMount
class NewMessages extends Rect.Component {
updateInterval;
componentDidMount() {
this.updateInterval = setInterval(() => {
this.props.getNewMessages();
}, 500);
}
componentWillUnmount() {
clearInterval(updateInterval);
}
render() {
return (
<div>
{this.props.newMessages}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment