React component

박진·2021년 3월 16일
0

컴포넌트 생명주기

리액트에서의 모든 component는 여러종류의 The Component Lifecycle을 갖는다. 이메서드를 오버라이딩하여 특정 시점에서 코드가 잘 실행될수있도록 활용및 사용하면 좋다.

Mounting

constructor()
static getDerivedStateFromProps()
render()
componentDidMount()

이순서로 DOM상에 삽입될때 순서대로 호출된다.

Updating

static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()

props 또는 state가 변경되면 갱신이 발생되는데, 아래 메서드들은 컴포넌트가 다시 렌더링될 때 순서대로 호출된다.

Unmounting

componentWillUnmount()

이 메서드는 컴포넌트가 DOM 상에서 제거될 때에 호출된다.

Error Handling

static getDerivedStateFromError()
componentDidCatch()

이 메서드들은 자식 컴포넌트를 렌더링하거나, 자식 컴포넌트가 생명주기 메서드를 호출하거나, 또는 자식 컴포넌트가 생성자 메서드를 호출하는 과정에서 오류가 발생했을 때에 호출된다.

profile
Hello :)

1개의 댓글

comment-user-thumbnail
2021년 3월 16일

오.. 정리 잘하셨는데요..! 많은 도움 받고 갑니다 :)

답글 달기