-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
API Calls shouldn't include the setStates within the function and should instead use the then on the promise. E.g. Like this:
componentDidMount() {
this.callApi()
.then(res => this.setState({ response: res.express }))
.catch(err => console.log(err));
}
callApi = async () => {
const response = await fetch("/api/hello");
const body = await response.json();
if (response.status !== 200) throw Error(body.message);
return body;
};
I also need to set up error handling on all my routes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels