import {useState,useEffect} from "react"
interface p3{
    url:string
}

export const useGetUrlParams=(props:p3)=>{
    const {url} = props
    const [state,setState] = useState<any>({})

    useEffect(()=>{
        if(url){
            const theRequest:any = {};
            if (url.indexOf("?") !== -1) {
                const str = url.slice(1);
                const strs = str.split("&");
                for(let i = 0; i < strs.length; i ++) {
                    const types = strs[i].split("=");
                    const key:string = types.shift()||'';
                    const value = types.join('=')
                    theRequest[key] = decodeURI(value.trim());
                }
            }
            setState(theRequest)
        }
    },[url])

    return state
}