profile
Creative Developer

이전값을 기억하는 Custom-hooks

Custom hooks 및 useRef 복습 !codesandbox[custom-hooks-useref-practice-forked-nydmm7?fontsize=14&hidenavigation=1&theme=dark] 처음 App.js 렌더링 될 때 그 시점에는 previousValue 값이 비어있으므로, 빈 값을 렌더링 하지만 이후 호출된 UsePrevious 내부에서는 current 값이 채워진다. 다음 버튼 클릭시 다시 App.js가 렌더링 되는데 prv~ 에서 이전에 채워진 ref.current 값을 가지고 렌더링 그러나 다른 이유로 버튼 클릭 없이 App.js가 렌더링되면 채워진 값을 다시 가져오므로 둘의 값이 같게된다.

2022년 3월 23일
·
0개의 댓글
·