import { useHistory } from 'react-router-dom'; interface UseQuery { query: Record; setQuery: (query: Record) => void; } const useQuery = (): UseQuery => { const history = useHistory(); const searchParams = new URLSearchParams(history.location.search); const query = Object.fromEntries(searchParams); const setQuery = (newQuery: Record): void => { const queryString = new URLSearchParams(newQuery); history.push({ search: `?${queryString}` }); }; return { query, setQuery }; }; export default useQuery;