首页 > 解决方案 > 此错误的问题“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>
      );
    }

标签: node.jsreactjs

解决方案


可能您没有为您的Context,

检查是否../App/AppProvider有一些调用React.createContext,检查您是否提供了prices一个空数组的对象。


推荐阅读