I want to call an arrow function inside itself in React.
I am fetching an api but if api response with status code 401, I do some things (that work as expect) and then I need to reexecute the function tokenGet. How can I do this? I tried this way below and with return tokenGet(url); and all ways result on a infinite loop on api.
const tokenGet = (url) => {
const data = {
...
};
return fetch(url, data)
.then(res => {
if (res.status === 401) {
...
tokenGet(url);
} else {
return res.json();
}
});
};
I am calling above function this way on another component.
useEffect(() => {
tokenGet(url)
.then(data => {
...
});
}, []);