Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react useeffect avoid initial render

const didMountRef = useRef(false);

useEffect(() => {

  // Are we on he initial render? No! Let's run some code:
  if ( didMountRef.current ) { 
    // Run some code...
  } else {
	  didMountRef.current = true;
  }    

}, [dependency]);
 
PREVIOUS NEXT
Tagged: #react #useeffect #avoid #initial #render
ADD COMMENT
Topic
Name
4+8 =