Roadmap to becoming a developer in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

16 lines
435 B

import { useEffect, useState } from "react";
export function useParams<T = Record<string, any>>(): T {
const [params, setParams] = useState<T>({} as T);
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const paramsObj: Record<string, any> = {};
for (const [key, value] of params.entries()) {
paramsObj[key] = value;
}
setParams(paramsObj as T);
}, []);
return params
}