Skip to content

Instantly share code, notes, and snippets.

@misss-popcorn
Created October 25, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misss-popcorn/893a21cd3e716fb5415759617d5c4939 to your computer and use it in GitHub Desktop.
Save misss-popcorn/893a21cd3e716fb5415759617d5c4939 to your computer and use it in GitHub Desktop.
import React from "react";
export default class UseEffectClass extends React.Component {
constructor() {
super();
this.interval = 0;
this.state = {
count: 0
};
}
componentDidMount() {
this.interval = setInterval(() => {
this.setState(prevState => ({
count: prevState.count + 1
}));
}, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<span className="Left">
<p>Class Component</p>
<p>{this.state.count}</p>
</span>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment