1 2 3 4 5 6 7 8 9 10
import { useRef, useEffect } from 'react'; export const usePrevious = value => { const ref = useRef(); useEffect(() => { ref.current = value; }); return ref.current; }