node.js - 此错误的问题“TypeError:无法读取未定义的属性'map'”
问题描述
TypeError: Cannot read property 'map' of undefined
这个错误不断出现,不会让我运行我的网站。任何帮助或帮助都会很棒。我只需要弄清楚究竟要改变什么才能让它运行。
import React from "react";
import styled from "styled-components";
import { AppContext } from "../App/AppProvider";
import PriceTile from "./PriceTile";
export default function() {
return (
<AppContext.Consumer>
{({ prices }) => (
<PriceGrid>
{prices.map((price, index) => (
<PriceTile key={`priceTile-${index}`} index={index} price={price} />
))}
</PriceGrid>
)}
</AppContext.Consumer>
);
}
解决方案
可能您没有为您的Context
,
检查是否../App/AppProvider
有一些调用React.createContext
,检查您是否提供了prices
一个空数组的对象。
推荐阅读
- android - Kotlin SQLite “(代码 1 SQLITE_ERROR):,编译时:INSERT INTO”
- javascript - 当我点击时汉堡菜单没有关闭
- javascript - 使用 match() 搜索数组中的多个值
- node.js - 如何读取用 NodeJs 编写的 AWS Lambda 中的表单数据?
- kubernetes - Kubernetes 中的 NodeIP、ClusterIP 和 LoadBalancer
- c++ - 如何编写 const 传播指针类型包装器?
- vhdl - 使用并发代码和顺序代码的VHDL混淆
- ldap - 使用 LDAP 配置 Hashicorp Vault 并限制登录
- java - Java:填写 PreparedStatement 的 SQLite 参数会导致错误
- javascript - NodeJS fetch() API 和 POST 请求