@fazzaamiarso
Posted
Hi @SoulRvr29! Great work on your project, the README is fantastic!
You can use 1 state for this project. Example
// `advice` become an object
const [advice, setAdvice] = useState({});
// then you can get the advice data
const adviceContent = advice.advice;
const adviceId = advice.id
useEffect(() => {
clickHandler();
}, []);
const clickHandler = () => {
fetch("https://api.adviceslip.com/advice")
.then((response) => {
if (response.ok) {
return response.json();
} else {
console.log("no data");
}
})
.then((data) => {
setAdvice(data.slip)
})
.catch((err) => {
console.log("Something went wrong!", err);
});
};
I hope it helps! Cheers!
Marked as helpful
@SoulRvr29
Posted
@fazzaamiarso You're right, I changed the code. Thanks for the help.