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.
API Calls shouldn't include the setStates within the function and should instead use the
thenon the promise. E.g. Like this:I also need to set up error handling on all my routes.