madiator.com/ui/effects/use-previous.js
2021-08-16 12:11:25 +02:00

11 lines
199 B
JavaScript

import { useEffect, useRef } from 'react';
export default function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
}