Created
October 25, 2020 16:36
-
-
Save misss-popcorn/893a21cd3e716fb5415759617d5c4939 to your computer and use it in GitHub Desktop.
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
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