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.
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
- Solution URL: Github solution URL
- Live Site URL: Live site URL
- JSX
- CSS custom properties
- Flexbox
- Mobile-first workflow
- React - JS library
- TailwindCSS - CSS framework
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]);
I look forward to learning and working with TypeScript
- Learn REST APIs - I understood better how RESTful API works after learning and practicing with some interactive examples.
- LinkedIn - Emerenini Cynthia Ngozi
- Frontend Mentor - @cindyeme
- Twitter - @CynthiaENgozi1