Fazza Razaq Amiarso• 2,360
@fazzaamiarso
Posted
Hi Amos! Great Work!
I have a quick tip for you. You can destructure your response like this.
const handleJoke = () => {
setError("");
axios
.get("https://api.adviceslip.com/advice")
.then((res) => {
const {
slip : { advice, id },
} = res.data;
setAdvice(advice);
setAdviceId(id);
})
.catch((err) => {
const errMessage = err.code === "ERR_NETWORK"
? "Make sure you're connected to the internet"
: "Something went wrong";
setError(errMessage);
});
};
I hope it helps! Cheers!
Marked as helpful
0