React Hook Dependency Array

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 Apr 22 3:17
Editor
Edited
Edited
2022 Mar 31 3:24
Refs
Refs
effect의 기본 동작은 모든 렌더링을 완료한 후 effect를 발생하는 것
의존성 중 하나가 변경된다면 effect는 항상 재생성
shallow Object Comparison 함
 
의존성 없으면 아예 callback 함수 안에 선언하면 의존성없에기 가능
의존성 전달 안하면 effect 안에 있는 props와 state는 항상 초깃값을 가지게 될 것
 
deep comparision하려면 use-deep-compare-effect 라는 hook library 쓰거나
useCustomCompareEffect 라이브러리도 있고
 
 
 
Ways to Handle Deep Object Comparison in useEffect hook
In React, side effects can be handled in functional components using useEffect hook. In this post, I'm going to talk about the dependency array which holds our props/state and specifically what happens in case there's an object in this array. The useEffect hook runs even if one element in the dependency array has changed.
Ways to Handle Deep Object Comparison in useEffect hook
Hooks API Reference - React
Hook 는 React 16.8에서 새로 추가된 개념입니다. Hook을 통해 class를 작성하지 않고도 state와 같은 React 기능들을 사용할 수 있습니다. 이 페이지는 React에 내장된 Hook API를 설명합니다. Hook이 생소하다면 Hook 개요를 먼저 읽어 보기 바랍니다. 혹은 frequently asked questions 에서 유용한 정보를 찾을 수도 있습니다. 상태 유지 값과 그 값을 갱신하는 함수를 반환합니다.
Hooks API Reference - React
 
 

Recommendations