简体   繁体   English

reactjs待办事项列表-未捕获的TypeError:无法读取未定义的属性'map'

[英]reactjs ToDo List- Uncaught TypeError: Cannot read property 'map' of undefined

I'm following the ReactJS tutorial ( http://redux.js.org/docs/basics/UsageWithReact.html ) for the basic todo list and tweaking it to my liking, but am running into the following error: 我正在遵循ReactJS教程( http://redux.js.org/docs/basics/UsageWithReact.html )中的基本待办事项列表,并根据自己的喜好进行调整,但是遇到以下错误:

Uncaught TypeError: Cannot read property 'map' of undefined

Here is the code: 这是代码:

ConfigList.js - ConfigList.js-

import React, {Component, PropTypes} from 'react';
import ConfigItem from '../components/ConfigItem';


const ConfigList = ({ configs }) => (
  <ul>
    {configs.map(config =>
      <ConfigItem
        key={config.id}
        />
    )}
  </ul>
);

ConfigList.propTypes = {
  configs: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.number.isRequired,
    text: PropTypes.string.isRequired
  }))
};

export default ConfigList;

ConfigItem.js - ConfigItem.js-

import React, { PropTypes } from 'react';

const ConfigItem = ({ text }) => (
  <li>{text}</li>
);

ConfigItem.propTypes = {
  text: PropTypes.string.isRequired
};

export default ConfigItem;

I'm new to ReactJS and somewhat new to Javascript so I'm hoping I get some feedback as to why I'm seeing this error, and what steps I can take to get past it. 我是ReactJS的新手,也是Javascript的新手,所以我希望我得到一些反馈,以了解为什么会看到此错误,以及可以采取哪些措施来克服该错误。

The error Cannot read property 'map' of undefined is saying that you're trying to call map() on something which doesn't exist. 错误Cannot read property 'map' of undefined表示您正在尝试在不存在的对象上调用map() The only place you're calling map() is in ConfigList : 您调用map()的唯一位置是在ConfigList

{configs.map(config =>
  <ConfigItem
    key={config.id}
    />
)}

which suggests that the configs variable hasn't been set when you're trying to call map() . 这表明在尝试调用map()时未设置configs变量。 Since ConfigList is a functional React component , configs is expected to be passed in as part of the props object, but it doesn't look like this is being set. 由于ConfigList功能性的React组件 ,因此希望将configs作为props对象的一部分传入,但是看起来好像没有设置它。

You'll need to check the code where you're calling <ConfigList /> to make sure you are setting configs ; 您需要检查调用<ConfigList />的代码,以确保您正在设置configs it should look a bit like 它看起来应该像

<ConfigList configs={ myConfigs } />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取未定义的属性“toLowerCase”(待办事项列表应用程序) - Uncaught TypeError: Cannot read property 'toLowerCase' of undefined (Todo list application ) reactjs-未捕获的TypeError:无法读取未定义的属性&#39;map&#39; - reactjs - Uncaught TypeError: Cannot read property 'map' of undefined 未捕获到的TypeError:无法读取ReactJs中{Component} .render上未定义的属性“ map” - Uncaught TypeError: Cannot read property 'map' of undefined at {Component}.render in ReactJs reactjs Uncaught TypeError:无法读取未定义的属性&#39;map&#39; - reactjs Uncaught TypeError: Cannot read property 'map' of undefined React.js-未捕获的TypeError:无法读取未定义的属性&#39;then&#39; - Reactjs - Uncaught TypeError: Cannot read property 'then' of undefined 类型错误:无法读取未定义的属性“地图”| ReactJS - TypeError: Cannot read property 'map' of undefined | ReactJS ReactJS:TypeError:无法读取未定义的属性“map” - ReactJS: TypeError: Cannot read property 'map' of undefined TypeError:无法读取 reactJS 上未定义的属性“映射” - TypeError: Cannot read property 'map' of undefined on reactJS Reactjs:类型错误:无法读取未定义的属性“地图” - Reactjs : TypeError: Cannot read property 'map' of undefined TypeError:无法读取 ReactJs 中未定义的属性“映射”? - TypeError: Cannot read property 'map' of undefined in ReactJs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM