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]);