It is my first time of using SWR. Maybe I am wrongly implementing it. After implementing the SWR wrapper, I continued to get endless and repeated API call to the same endpoint. I saw this when I checked the Network tab of my browser: Here is how I implemented it.
const getProfile = async () => {
try {
const res = await axiosPrivate.get<axiosGetCompanyProfile>(`/getcompany`, {
withCredentials: true,
headers: { Authorization: `${state?.in_memory}` },
});
console.log(res?.data, 'pro')
return res.data;
} catch (error) {
throw error;
}
};
const { data:fetchProfile, error, isLoading } = useSWR('/api/data', getProfile);
//fetch profile
useEffect(()=>{
if(fetchProfile){
dispatch({type: actionEnum.COMPANY_PROFILE_DATA, payload: fetchProfile });
return
}
}, [isLoading]);
I noticed that the API calls happens whenever I leave the browser and returns. But from the look of things, it doesnt hit my server. So, why is it recalling it? Here is a screnshot: