I am quite new to javascript and I have this issue. The return part doesn´t wait for my status from fetch. How can I make this happen ? I also tried to add some timeouts but that didnt work as well.
const LoggedRoute = ({ component: Component, ...rest}) => {
const token = cookie.get('token');
fetch(`${constants.urls.put}/auth/user`, {
method: 'GET',
headers:{'Authorization': 'Token ' + token}
})
.then(
data => {
data.json();
status = data.statusText;
}
)
return (
<Route
{...rest}
render={props =>
((status != "OK")) ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: "/",
state: { from: props.location}
}}
/>
)
}
/>
);
}
export default LoggedRoute