Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Advice generator app with REACT

#react#accessibility
Amos 470

@fistty

Desktop design screenshot for the Advice generator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


-💡 Added network error notification. -💡 Added rotation to the dice icon on hover.

Community feedback

@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

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord