我正在尝试使用fortnite api显示当前商品商店,并且标题中出现错误,当我控制台日志结果时,它显示一个数组,但我无法通过它映射?为什么?
import React, { useState, useEffect } from 'react'
import axios from 'axios';
export default function itemShop() {
const [shop, setShop] = useState('')
const API = 'https://fortnite-public-api.theapinetwork.com/prod09/store/get?language={en}'
useEffect(() => {
const fetchData = async () => {
const result = await axios(
API,
);
setShop(result.data);
};
fetchData();
}, []);
const { items } = shop;
console.log(items)
return (
<div>
<p>{shop.date}</p>
{items.map(item => <p>{item.name}</p>)}
</div>
)
}
代码沙箱:https : //codesandbox.io/embed/km10wq4y5
相关分类