Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyComponent extends React.Component {
- componentDidMount() {
- this.isMounted = true;
- }
- componentWillUnmount() {
- this.isMounted = false;
- }
- render() {
- return (
- <div>
- {this.state.now}
- </div>
- );
- }
- updateTimeEverySecond() {
- setInterval(() => {
- if (this.isMounted) {
- this.setState({
- now: new Date().toISOString(),
- });
- }
- }, 1000);
- }
- }
Add Comment
Please, Sign In to add comment