useUpdateEffect

useUpdateEffect

import {useEffect, useRef} from "react"; const useUpdateEffect:(callback:Function,dependencies:any[])=>void =(callback:Function,dependencies:any[])=>{ const firstRenderRef = useRef(true); useEffect(()=>{ if(firstRenderRef.current) { firstRenderRef.current =false; return; } return callback(); },dependencies); } export default useUpdateEffect;

useEffect doesnt care whether is is first render. useUpdateEffect check and when first rendered, it doenst eroute callback effect.

공유하기 글 요소 저작자표시

from http://taesic.tistory.com/29 by ccl(A) rewrite - 2022-01-01 11:27:34