首页 > 其他分享 >学习笔记jira项目25用fetch抽象http请求

学习笔记jira项目25用fetch抽象http请求

时间:2023-02-12 22:06:52浏览次数:41  
标签:jira 25 http ... return token user const config


// TS 中的typeof,是在静态环境运行的
// return (...[endpoint, config]: Parameters<typeof http>) =>
export const useHttp = () => {
const { user } = useAuth();
// utility type 的用法:用泛型给它传入一个其他类型,然后utility type对这个类型进行某种操作
return useCallback(
(...[endpoint, config]: Parameters<typeof http>) =>
http(endpoint, { ...config, token: user?.token }),
[user?.token]
);
};
const bootstrapUser = async () => {
let user = null;
const token = auth.getToken();
if (token) {
const data = await http("me", { token });
user = data.user;
}
return user;
};

标签:jira,25,http,...,return,token,user,const,config
From: https://blog.51cto.com/u_15460007/6052213

相关文章