This is my first time using react-query and I having problem request data from API.
This is the code:
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
import "./App.css";
function App() {
const fetchData = async () =>{
const { data } = await axios.get("https://api.jikan.moe/v4/anime");
const response = data.data;
return response
}
const { isLoading,data,isError } = useQuery(
["posts"],
fetchData,
{
retry: false,
refreshInterval: 0,
staleTime: 0
}
);
if (isLoading) return <h1>...Loading</h1>;
if (isError) return <h1>Fail</h1>;
console.log(data)
return (
<div className="App">
{data.map((datas)=>{
<div>
{datas.title}
</div>
})}
</div>
);
}
export default App;
When I console.log(data) it does show the list of data Array of 25 object element.
But when I try the use data.map to show the data in the web site nothing appear but It does appear if I only try the show one of the array like
{data[0].title}
the data does appear but when I try the show all array element with data.map but nothing seems to appear. Can someone help me?