useLayoutEffect 에 대해 알아보기
·
Stack/React
useLayoutEffect란?useLayoutEffect와 useEffect는 거의 비슷한 역할을 한다.useEffect(() => { //...}, [state]) useLayoutEffect(() => { //...}, [state]) 구조도 비슷하고 기능도 비슷한데 다른점은 effect가 실행되는 시점이다.useEffect의 경우 화면이 업데이트된 이후에 effect가 실행된다.useLayoutEffect는 effect 실행 이후에 화면이 업데이트가 된다.useLayoutEffect를 통해 생기는 이점은 effect를 먼저 실행하기 때문에 사용자가 보는 UI를 보다 정교하게 보일 수 있다.코드로 알아보기'use client';import { useEffect, useLayoutEffec..