Skip to content

cindyeme/advice-generator-app

Repository files navigation

Frontend Mentor - Advice generator app solution

This is a solution to the Advice generator app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the app depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Generate a new piece of advice by clicking the dice icon

Screenshot

Desktop-Design Desktop-Active-State Mobile-Design Mobile-Active-State

Links

My process

Built with

  • JSX
  • CSS custom properties
  • Flexbox
  • Mobile-first workflow
  • React - JS library
  • TailwindCSS - CSS framework

What I learned

I learned how to use fetch API and some react hooks to fetch and display data from an endpoint.

Some code snippet:

  // state for updating advice(s)
  const [slip, setSlip] = useState({
    id: "117",
    advice:
      "It is easy to sit up and take notice, what's difficult is getting up and taking action",
  });
  // indicates loading
  const [loading, setLoading] = useState(false);

  // generate new advice
  const generateAdvice = useCallback(() => {
    setLoading(true);
    fetch(API_URL, api)
      .then(resp => resp.json())
      .then(data => {
        setSlip(data.slip)
        setLoading(false);
      })
      .catch(err => {
        console.log(err);
        setLoading(false);
      });
  }, [setSlip]);

  useEffect(() => {
    generateAdvice();
  }, [generateAdvice]);

Continued development

I look forward to learning and working with TypeScript

Useful resources

  • Learn REST APIs - I understood better how RESTful API works after learning and practicing with some interactive examples.

Author