diff --git a/webapp/src/hook/Previous.js b/webapp/src/hook/Previous.js new file mode 100644 index 0000000..d3e03ca --- /dev/null +++ b/webapp/src/hook/Previous.js @@ -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]); +} + +*/ \ No newline at end of file