I’m trying to get data from API
but. I’m getting this error Error Image.
Here is my code.
const [datas, setDatas] = useState(" ");
const res = async () => {
const response = await axios.get("http://hasanadiguzel.com.tr/api/kurgetir");
setDatas(response.data.TCMB_AnlikKurBilgileri);
};
datas.map((item) => {
return (
<KurCard
title={item.Isim}
alis={item.BanknoteBuying}
satis={item.BanknoteSelling}
/>
);
});
How can I solve this?
I’m trying to map()
datas, because I need it
2
Answers
Assuming your API request is valid, you would need to actually return something from the component itself and not just the array:
Hi @n00b,
The data that
datas
is initially being set to an empty string, which does not have a map method. First, you need an empty array instead of an empty stringuseState([])
. Now you canmap
.