UNPKG

react-hook-granth

Version:

A collection of custom React hooks for efficient state management and UI logic.

17 lines (13 loc) 322 B
import { useEffect, useRef } from "react"; /** * Store the previous value of a state or prop. * @param {*} value * @returns {*} previous value */ export default function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }, [value]); return ref.current; }