【问题标题】:cannot read property 'map of undefined无法读取属性'未定义的映射
【发布时间】:2017-07-15 07:07:05
【问题描述】:

我收到此错误:

无法读取未定义的新属性“地图” index.android.bundle?platform=android&dev=false&hot=false&minify=false:87221:34 ReactCompositeComponentWrapper._constructComponentWithoutOwner index.android.bundle?platform=android&dev=false&hot=false&minify=false:31251:30 ReactCompositeComponentWrapper._constructComponent index.android.bundle?platform=android&dev=false&hot=false&minify=false:31247:21 ReactCompositeComponentWrapper.mountComponent index.android.bundle?platform=android&dev=false&hot=false&minify=false:31231:25 Object.mount 组件 index.android.bundle?platform=android&dev=false&hot=false&minify=false:30937:39 Object.updateChildren index.android.bundle?platform=android&dev=false&hot=false&minify=false:32163:69 Constructor._reconcilerUpdateChildren index.android.bundle?platform=android&dev=false&hot=false&minify=false:32271:119 构造函数._updateChildren index.android.bundle?platform=android&dev=false&hot=false&minify=false:32308:33 Constructor.updateChildren index.android.bundle?platform=android&dev=false&hot=false&minify=false:32302:14 构造函数.receiveComponent index.android.bundle?platform=android&dev=false&hot=false&minify=false:32375:119

main.js

 import icons from './icons'       

  type Cell = {
      image: any,
      animation: any
    };

    export default class Camera extends React.Component {
      cells: Cell[];
      background = new Animated.Value(HIDDEN);
      text = new Animated.Value(HIDDEN);
      state: { focused?: Cell } = {};

      constructor(props) {

        super(props);
        this.cells = icons.map((icon) => ({
          ...icon, animation: new Animated.Value(HIDDEN)
        }));


      }

icons.js

import React from 'react';
import Icon from 'react-native-vector-icons/Octicons'
import SimpleLineIcons from 'react-native-vector-icons/SimpleLineIcons'

const icons =[
  { name: 'Notes', image: <Icon name='device-camera' />},
  { name: 'Earth', image: <SimpleLineIcons name='camera' /> }
]

export { icons }

【问题讨论】:

  • 你登录了吗icons,好像是undefined
  • @adeneo 是的,它显示未定义,不知道为什么?
  • 那么import icons from './icons' 可能并没有按照你的想法去做。
  • @adeneo 或者 export { icons } 不起作用,不知道问题出在哪里。
  • 如果问题是 icons 没有正确导入,我或其他任何人都不会这样做?

标签: javascript reactjs react-native react-native-android map-function


【解决方案1】:

icons.js 内的export default icons; 应该可以解决问题。

【讨论】:

  • 我昨天试过但没用,今天又试了一次,它开始工作了。这是 JS,没有人知道会发生什么以及为什么!
  • 哈哈。你必须喜欢 JS,它的怪癖:P
猜你喜欢
  • 1970-01-01
  • 2021-08-12
  • 2018-01-07
  • 2022-06-21
  • 2021-08-31
  • 2017-05-21
  • 1970-01-01
  • 2021-08-05
相关资源
最近更新 更多