Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t将未定义的转换为对象(object.keys()函数)_Javascript_Reactjs_React Redux - Fatal编程技术网

Javascript Can';t将未定义的转换为对象(object.keys()函数)

Javascript Can';t将未定义的转换为对象(object.keys()函数),javascript,reactjs,react-redux,Javascript,Reactjs,React Redux,我正在尝试迭代redux存储并呈现所有存在的对象。在尝试创建对象数组时,我遇到以下错误 相关代码段: class VictoryChartComp extends React.Component{ constructor(props) { super(props); //this.ChartsArray = []; this.ChartsArray = Object.keys(this.props.newcharts).map(function (key) { if (th

我正在尝试迭代redux存储并呈现所有存在的对象。在尝试创建对象数组时,我遇到以下错误

相关代码段:

class VictoryChartComp extends React.Component{
constructor(props) {
  super(props);
  //this.ChartsArray = [];
  this.ChartsArray = Object.keys(this.props.newcharts).map(function (key) {
    if (this.props.newcharts.type == 'victory') {
    var item = this.props.newcharts[key];
    return item;
  }
}); 
}
整个代码可在此处找到:

我还试图声明'this.ChartsArray'(注释行),但问题仍然存在


任何帮助都将不胜感激

我在您的沙箱上测试了这一点,修复错误的方法当然是验证
this.props.newcharts
不是
null
未定义的
。从
VictoryChartComp.js

this.ChartsArray = this.props.newcharts
  ? Object.keys(this.props.newcharts).map(function(key) {
    if (this.props.newcharts.type === "victory") {
      var item = this.props.newcharts[key];
        return item;
      }
    })
  : [];
如果
This.props.newCharts
null
,则这将允许不定义
ChartsArray


尽管这解决了控制台错误,并允许组件将其呈现为空白-因为newCharts在我的执行中未定义。我不确定这是否是你真正想要的。您可能需要设置
newCharts

首先检查this.props.newCharts此变量是否有值,无法运行沙盒。一些firebase错误-
没有创建firebase应用程序“[默认]”-调用firebase应用程序。initializeApp()
你能在
Recharts.js
文件中检查这一行吗:
从“react dom”导入{render}
为什么这样使用
渲染
呢?如果你在'index.js'(第23行)中取消对firebase初始化应用程序的注释,应该可以使用。@salman.zare使用
渲染
完全可以