How do I render data from this api I want to render Advice from this api
fetch("https://api.adviceslip.com/advice")
You can try:
import React, { useState, useEffect } from 'react';
export default function App() {
const [advices, setAdvices] = useState([]);
console.log(advices); // you should have the fetch data here
async function fetchData() {
try {
const response = await fetch('https://api.adviceslip.com/advice');
const data = await response.json();
setAdvices(data.slip);
} catch (error) {
console.error(error);
}
}
useEffect(() => {
fetchData();
}, []);
return <></>;
}