Skip to content

Instantly share code, notes, and snippets.

@AsbDaryaee
Created October 25, 2024 17:25
Show Gist options
  • Save AsbDaryaee/b91768637e62074611e0bfb8aacaba6f to your computer and use it in GitHub Desktop.
Save AsbDaryaee/b91768637e62074611e0bfb8aacaba6f to your computer and use it in GitHub Desktop.
React useEffect Hook that Skips First Render
import { useEffect, useRef } from 'react';
function useSkipFirstRenderUseEffect(callback: () => void, dependencies: [any]) {
const firstRenderRef = useRef(true);
useEffect(() => {
if (firstRenderRef.current) {
firstRenderRef.current = false;
return;
}
callback();
}, dependencies);
}
export default useSkipFirstRenderUseEffect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment