usePrevious hook

This commit is contained in:
djmil 2023-11-10 13:17:38 +01:00
parent cd62d90de8
commit 6427844da3

View File

@ -0,0 +1,24 @@
import { useRef, useEffect } from 'react';
export default function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
/* Usage example
const useLocationChange = (action) => {
const location = useLocation();
const prevLocation = usePrevious(location);
useEffect(() => {
action(location, prevLocation);
}, [location]);
}
*/