usePrevious hook
This commit is contained in:
parent
cd62d90de8
commit
6427844da3
24
webapp/src/hook/Previous.js
Normal file
24
webapp/src/hook/Previous.js
Normal 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]);
|
||||
}
|
||||
|
||||
*/
|
Loading…
Reference in New Issue
Block a user