1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-04 05:46:37 -04:00
Files
jarv.is/hooks/useUpdateEffect.ts
2022-07-25 13:11:40 -04:00

16 lines
435 B
TypeScript

import { useEffect } from "react";
import useFirstMountState from "./useFirstMountState";
// identical to `useEffect()` but ignores the first invocation
const useUpdateEffect: typeof useEffect = (effect, deps) => {
const isFirstMount = useFirstMountState();
useEffect(() => {
if (!isFirstMount) {
return effect();
}
}, deps); // eslint-disable-line react-hooks/exhaustive-deps
};
export default useUpdateEffect;