Skip to content

Instantly share code, notes, and snippets.

@avcs06
Last active June 29, 2022 08:32
Show Gist options
  • Save avcs06/4ac2ef7f6eb3828900ef6e687ad003b3 to your computer and use it in GitHub Desktop.
Save avcs06/4ac2ef7f6eb3828900ef6e687ad003b3 to your computer and use it in GitHub Desktop.
Follows the changes of dependencies except the first one
import { useEffect, useRef } from 'react';
const useLazyEffect = (callback, deps) => {
const firstRender = useRef(true);
useEffect(() => {
if (firstRender.current) {
firstRender.current = false;
} else callback();
}, deps);
};
export default useLazyEffect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment