我第一次尝试在Next.js中使用SWR。我正在使用Axios进行HTTP调用。Axios调用受保护的API路由,我使用拦截器处理。这里是我使用SWR的地方之一,但当我从SWR
得到console.log(data)
时,我得到了undefined
;
const getProfile = async()=>{
try {
const res = await axiosPrivate.get<axiosGetCompanyProfile>(`/getcompany`, {withCredentials: true, headers: {Authorization: `${state?.in_memory}`}});
console.log(res.data, 'mmmmnn')
return res.data;
} catch (error) {
return error
}
}
const { data, error, isLoading } = useSWR(`${getcompany`, getProfile)
字符串
我做错了什么?
1条答案
按热度按时间bgtovc5b1#
有一个语法错误:
字符串
useSWR的第一个参数应该是一个字符串,作为标识数据的键(通常是API端点)。第二个参数是fetcher函数,在本例中是getProfile。