UNPKG

@rozhkov/react-useful-hooks

Version:
12 lines (9 loc) 249 B
import {useEffect, useRef} from 'react'; const usePrevious = <T>(value: T): T | undefined => { const ref = useRef<T | undefined>(undefined); useEffect(() => { ref.current = value; }); return ref.current; }; export default usePrevious;