Advertisement
butbanksy

Untitled

Jan 18th, 2021
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react"
  2.  
  3. export default class LifeCycle extends Component {
  4.     constructor(props) {
  5.         super(props)
  6.         this.state = {
  7.             favoriteColor: "red"
  8.         }
  9.     }
  10.     componentDidMount(){
  11.         setTimeout(() => {
  12.             this.setState({
  13.                 favoriteColor: "yellow"
  14.             })
  15.         }, 2000);
  16.     }
  17.  
  18.     componentDidUpdate(){
  19.         console.log("Rerender");
  20.     }
  21.  
  22.     componentWillUnmount(){
  23.        
  24.     }
  25.  
  26.     render() {
  27.         return (
  28.             <h1>
  29.                 My favorite color is {this.state.favoriteColor}!
  30.             </h1>
  31.         )
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement