reactjs - 应用程序不会运行 TypeError:无法读取未定义的属性“地图”
问题描述
我一直在地图上遇到这个问题,但无法弄清楚原因。
export default function() {
return (
<AppContext.Consumer>
{({ prices }) => (
<PriceGrid>
{prices.map((price, index) => (
<PriceTile key={`priceTile-${index}`} index={index} price={price}/>
))}
</PriceGrid>
)}
</AppContext.Consumer>
);
}
解决方案
最有可能的价格在某些时候不是数组...您可以进行类型检查,如果价格是数组以外的任何类型,它将跳过;
{Array.isArray(prices) && prices.map((price, index) => (
<PriceTile key={`priceTile-${index}`} index={index} price={price}/>
))}
推荐阅读
- c# - Xamarin forms with .netStandard 2.0, can't reference Core
- c - 用特殊情况更新矩阵
- mysql - SQL 错误 1452 而 UPDATE 非关键列
- mpi - Python 中的 mpi4py 或多处理?
- php - 使用 jQuery 触发动态按钮 ID
- javascript - 无法检测到用户何时到达手机浏览器的末尾
- swift - uiactivity 和 uiwebview 委托
- javascript - RXJS6 - 从返回 Observable 的 Promise 函数返回 Observable?
- cuda - 64位线程分离共享内存最小化bank冲突的策略
- java - JMS如何读取队列中的多个文件