小编典典

未捕获(承诺)TypeError:无法读取未定义的属性'createElement'(...)

reactjs

我需要将我的无状态功能组件重构为一个类。但是,这样做的时候,我总是收到错误消息,好像React本身是未定义的。

import React from 'react';
import { Cell } from 'fixed-data-table';

const DataCell = ({rowIndex, columnKey, data, onMessageClicked, ...props}) => {
  return (
    <Cell {...props} onClick={onMessageClicked(data[rowIndex].Id)}>
      {data[rowIndex][columnKey]}
    </Cell>
  );
};

export default DataCell;

import { React, Component } from 'react';
import { Cell } from 'fixed-data-table';

class DataCell extends Component {

  onCellClicked() {
    this.props.onMessageClicked(this.props.data[this.props.rowIndex].Id);
  }

  render() {
    const {rowIndex, columnKey, data, ...props} = this.props;
    return (
      <Cell {...props} onClick={onCellClicked}>
        {data[rowIndex][columnKey]}
      </Cell>
    );
  }
}

export default DataCell;

bundle.js:43248 Uncaught (in promise) TypeError: Cannot read property 'createElement' of undefined(…)

当我去那条线时,我看到

return _react.React.createElement(

我不明白 如何调试/修复此问题?

如果我发布的代码与某种原因无关,则此应用程序的完整代码在此处

谢谢!


阅读 719

收藏
2020-07-22

共1个答案

小编典典

哦…

import { React, Component } from 'react';

需要是

import React, { Component } from 'react';

:)

2020-07-22