리액트에서 Component 를 만들 때 class와 function 차이
Last updated 2 years ago
16.8 이전 버전
state 관리 가능, 라이프 사이클 메서드 사용
상태관리 불가, 정적데이터 보여줄 때만 사용했음
16.8 버전부터
동일
클래스 방식 어려움,
this의 반복 사용
this
라이프 사이클 사용시 반복 코드 많아짐, 복잡해지고 이해가 어려워짐
함수형 프로그래밍이 유행
class Welcome extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } }
function Welcome(props) { return <h1>Hello, {props.name}</h1>; }
를 이용해서 상태관리, 라이프 사이클을 사용할 수 있다.