티스토리 뷰
💡 React@17 부터 `componentWillMount`, `componentWillUpdate`, `componentWillReceiveProps`는 deprecated 되었다.
Mount
컴포넌트가 DOM에 붙는 과정.
- context, defaultProps, state 저장
- componentWillMount 메소드 호출 [react@17 deprecated]
- render메소드로 컴포넌트 DOM에 부착 (여기까지도 마운트 중에 속함)
- 마운트 완료 지점에서 componentDidMount 메소드 호출
- componentDidMount에서 DOM 접근 가능
- 이 시점에 비동기요청 또는 setTimeout, setInterval 실행
Props Update
props가 변경될 때의 과정.
- 업데이트 발생 감지하여 componentWillReceiveProps 메소드 호출 [react@17 deprecated]
- shouldComponentUpdate 메소드 호출
- 이 시점에 render(업데이트 완료) 전이기 떄문에 return false 로 render를 취소할 수 있음 (성능 최적화)
- 쓸 때 없는 업데이트는 여기서 걸러져야 함
- componentWillUpdate 메소드 호출 [react@17 deprecated]
- 이 시점엔 props를 업데이트하지 않은 상태이기 떄문에 해당 시점엔 state를 변경하면 안된다. (주의)
- 업데이트 완료 시점(render)
- componentDidUpdate 메소드 호출
- componentDidUpdate는 업데이트가 된 후이기 때문에 이전의 props 정보도 가지고 있음
State Update
setState() 호출을 통해서 state가 업데이트 될 때의 과정.
해당 과정은 props의 과정과 같다. 다만 componentWillReceiveProps는 호출하지 않는다.
자세한 설명은 Props Update에서 확인하면 된다.
- shouldComponentUpdate
- componentWillUpdate [react@17 deprecated]
- render
- componetDidUPdate
Unmount
컴포넌트가 제거되는 과정.
- componentWillUnmount
해당 메소드에서 이벤트 리스너를 제거하는 등의 정리를 진행한다.
Error
React 16부터 error를 캐치할 수 있게 되었다.
componentDidCatch 메서드를 통해서 에러 발생시에 대해 이벤트를 생성가능하게 됐다.
componentDidCatch(error, info) {
// ...
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- vue.js
- props
- 자바스크립트
- component
- Aria
- Issue
- vue
- 수영하기전후기
- 커리패턴
- 환경설정
- frontend
- 리액트생명주기
- youtube
- 퍼블리셔
- 수영전후기
- ES5
- 포세이돈되기까지
- API
- curring
- 웹퍼블리셔
- jeonst
- css3
- 퍼블리싱
- WAI-ARIA
- 웹퍼블리싱
- 이론공부
- 웹접근성
- javascript
- jQuery
- js
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함