import { useRef } from "react"; import { useDidUpdate } from "hooks"; /** * * @kind 12-State */ export const usePrevious = (value: T, initialValue?: T): T | undefined => { const storedValue = useRef(initialValue); useDidUpdate( () => { storedValue.current = value; }, [value], true, ); return storedValue.current; };