【问题标题】:React - Warning: React.createElement: type should not be null, undefined, boolean, or numberReact - 警告:React.createElement:类型不应为 null、未定义、布尔值或数字
【发布时间】:2016-12-09 03:19:27
【问题描述】:

我正在尝试在我的项目中实现这个chart

见Codepen

在我的 React 应用程序中,我创建了这个名为 ChartsGrid 的组件,我在其中导入 LineChart from './d3/LineChart' 及其子组件 HorizontalAxis、VerticalAxis 和 LinePlot

data 的状态是正确构建的,我在控制台中看到它

import React from 'react';
import Chart from './Chart';
import LineChart from './d3/LineChart';

export default class ChartsGrid extends React.Component{

  render() {

    const view = [480, 320];
    const trbl = [0, 0, 0, 0]
    const horizontalAxisHeight = 30;
    const verticalAxisWidth = 42;
    const { data } = this.props;

    return (
      <div className="grid">
          <LineChart {...{view, trbl, data, horizontalAxisHeight, verticalAxisWidth}} />
      </div>
    )
  }
};

我在控制台中收到此错误

它抱怨我在ChartsGrid 中的渲染方法,我真的不明白什么可能是错的。在我看来,所有设置都很好,在 previous codepen example 中唯一的区别是它在 setTimeout 函数中呈现折线图数据。

我在这里做错了什么?

【问题讨论】:

    标签: javascript reactjs d3.js charts redux


    【解决方案1】:

    添加一个console.log('!!!!', LineChart) 并查看它是否已定义。也许您在导入/导出时出错了

    【讨论】:

    • 是的,导入/导出不匹配是此错误的最常见原因。鉴于 &lt;LineChart> 是唯一被渲染的其他东西,很可能它没有被正确导入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 2016-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 2016-09-10
    相关资源
    最近更新 更多