import Taro, { getCurrentInstance } from "@tarojs/taro";
import { useContext, useMemo } from "react"
import { RouteComponentContext } from "../provider/route";


export const useParams = <T,>(): T => {

    // return React.useMemo(() => {
    //     return getCurrentInstance().router?.params as any || {};
    // }, [])
    const routeContext = useContext(RouteComponentContext);
    return useMemo(() => {
        if (Taro.getEnv() === Taro.ENV_TYPE.WEB) {
            return (routeContext.data.params || {}) as T;
        }
        return (getCurrentInstance().router?.params || {}) as T;
    }, [])
}