componentWillUnmount1 [리액트] 라이프사이클 useEffect와 componentDidMount, componentDidUpdate, componentWillUnmount 비교하기 1. mount 컴포넌트가 브라우저에 렌더링될 때 실행 componentDidMount componentDidMount() { // 렌더링 시 실행될 코드 } useEffect와 빈배열 useEffect(컴포넌트가 브라우저에 렌더렝될때 실행할 함수, []); 2. update 컴포넌트 내부 특정 요소가 업데이트될 때 실행 componentDidUpdate componentDidUpdate(prevProps, prevState) { // 업데이트 되기 이전의 Props, State 값을 받아옴 // 업데이트 된 값과, 업데이트 되기 이전의 값을 직접 비교해서, 함수를 실행시킴 // 모든 props, state 값중 하나라도 변경사항이 있을 경우 실행할 코드를 이곳에 넣는다 if (this.props.num.. 2022. 8. 9. 이전 1 다음