Class Component, Function Component

리액트에서 Component 를 만들 때 class와 function 차이

class, function 방식의 차이

class 방식
function 방식

16.8 이전 버전

state 관리 가능, 라이프 사이클 메서드 사용

상태관리 불가, 정적데이터 보여줄 때만 사용했음

16.8 버전부터

동일

React 공식 - Hooksarrow-up-right를 이용해서 상태관리, 라이프 사이클을 사용할 수 있다.

함수 방식 유행 이유

class 방식

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

function 방식

참고

Last updated