i am trying to consume from an API using useSWR() libary and the data to be return is an array of objects so i decided to try the axios method at first to make the request by doing below
const fetcher = (url) => axios.get(url).then((resp) => resp.json());
But this fetcher didnt work so i tried using the fetch method and i noticed the data was retrieved but i tried mapping, it was giving me an arror that says data.map is not a funtion.
const fetcher = (...args) => fetch(...args).then((resp) => resp.json());
function Swr() {
const { data, error } = useSWR(
"https://callcaree.herokuapp.com/api/member",
fetcher,
{ suspense: true }
);
//the data
console.log(data);
if (error) {
return <h1> There was an error!</h1>;
}
return (
<div>
{data?.map((props) => {
<div key={props._id}>
<h3>{props.title}</h3>
</div>;
})}
</div>
);
}