1 import { useEffect } from 'react';
2 import { useHistory, useLocation } from 'react-router-dom';
4 const useSearchParamsEffect = (cb: (params: URLSearchParams) => URLSearchParams | undefined, deps: any[]) => {
5 const history = useHistory();
6 const location = useLocation();
8 const params = new URLSearchParams(location.search);
9 const result = cb(params);
11 history.replace({ ...location, search: result.toString() });
13 }, [location.search, ...deps]);
16 export default useSearchParamsEffect;