类型错误:无法为 useState ReactJS 读取未定义的属性“地图”

时间:2021-07-19 11:16:51

标签: javascript reactjs react-hooks

我是 React 的新手。 setplantListResponse 使用 fetch 从 API 获取数据。这是我用于获取数据并将其存储在 plantItems 中的代码。

export default function HomePage() {
const [plantItems, setplanItems] = React.useState([]);
const [plantListResponse, setplantListResponse] = React.useState("");
const fail = async (text) => {
    console.log("Error!", text);
    window.location = "/";
};

useEffect(() => {
    getPlantList((plantListResponse) => { setplantListResponse(plantListResponse) }, fail);
    setplanItems(plantListResponse.plantList);
    console.log(plantItems);
}, []);

......

作为函数的回报,我正在尝试使用

{plantItems.map((plant) => {

但我收到 TypeError:无法读取植物项未定义的属性“地图”。

0 个答案:

没有答案