This is a solution to the Advice generator app challenge on Frontend Mentor.
- SCSS
- Flexbox
- CSS Grid
- React JS
- laptop-first workflow
I understood how to handle http requests and make use of the useEffect hook when programming asynchronously.
useEffect(() => {
let data;
const getAdvice = async () => {
try {
if (hasLoaded) {
const res = await fetch("https://api.adviceslip.com/advice");
if (!res.ok) {
throw new Error("Something went wrong!!");
}
const adviceData = await res.json();
for (const key in adviceData) {
data = adviceData[key];
}
setAdvice(data);
}
} catch (err) {
console.log(err.message);
}
};
getAdvice();
}, [hasLoaded]);
- Frontend Mentor - @ejim11
- Twitter - @favourejim56