I am a learner of React and I have some problems with my .map statement. I fetch the data from API and I keep the data using useState. But when I wanted to map the state it’s not working and it says Uncaught TypeError: dates.map is not a function. Could you please help me to write? I wanted to write in the div element.
import { useState, useEffect } from "react";
function LabelParams() {
const url = ""
let [dates, setDates] = useState([]);
useEffect(() => {
requestDate();
}, []);
async function requestDate() {
const res = await fetch(url);
const json = await res.json();
console.log(json)
setDates(json.dates);
}
return (
<div>
{
dates.map() //something like this
}
</div>
)
}
export default LabelParams;