이 글은, 노마드코더의 "ReactJS로 영화 웹 서비스 만들기"를 공부한 내용을 수강자 입장에서 필기한 것으로, 
다소 불친절한 설명이 있을 수 있음을 미리 알립니다.
# Mounting
- 
Component가 mounting될 때
- 
constructor()실행 - 
static
getDerivedStateFromProps()실행 - 
componentDidMount()실행class App extends React.Component { constructor(props) { super(props); console.log("hello"); } state = { count: 0, }; componentDidMount() { console.log("component rendered"); } render() { console.log("I am render"); } } 
 - 
 
결과

# Updating
- Component가 Updating될 때
- static 
getDerivedStateFromProps()실행 shouldComponentUpdate()실행render()실행getSnapshotBeforeUpdate()실행componentDidUpdate()실행
 - static 
 
import React from "react";
class App extends React.Component {
  constructor(props) {
    super(props);
    console.log("hello");
  }
  state = {
    count: 0,
  };
  componentDidMount() {
    console.log("component rendered");
  }
//### componentDidUpdate ### //
  componentDidUpdate() {
    console.log("I just updated.");
  }
  render() {
    console.log("I am render");
    return (
      <div>
        <h1>The number is: {this.state.count}</h1>
        <button onClick={this.add}>Add</button>
        <button onClick={this.minus}>Minus</button>
      </div>
    );
  }
  add = () => {
    this.setState((current) => ({ count: current.count + 1 }));
  };
  minus = () => {
    this.setState((current) => ({ count: current.count - 1 }));
  };
}
export default App;

add 또는 minus 를 클릭하면,

# Unmounting
- Component가 Unmounting될 때
componentWillUnmount()실행
 
'JavaScript > React' 카테고리의 다른 글
| React Axios로 API에서 받아온 데이터 확인 # 4.1. Rendering the Movies (0) | 2020.06.29 | 
|---|---|
| React Axios로 API 가져오기 #4.0. Fetching Movies from API (0) | 2020.06.29 | 
| React의 Class Component와 State #3.0. Class Components and State (0) | 2020.06.29 | 
| React PropTypes 사용법: #2.4 Protection with PropTypes (0) | 2020.06.29 | 
| # 2.2 Dynamic Component Generation #2.3 map Recap (0) | 2020.06.29 |