UNPKG

reactuals

Version:

A useful package providing a collection of 50+ React hooks and utilities to simplify React development.

22 lines (21 loc) 541 B
import { useEffect, useRef } from "react"; /** * A hook that runs an effect only on updates, not on initial mount. * * Example: * useUpdateEffect(() => { * // Effect logic here * }, [value]); */ export function useUpdateEffect(effect, deps) { const isInitialMount = useRef(true); useEffect(() => { if (isInitialMount.current) { isInitialMount.current = false; } else { return effect(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, deps); }