我需要将我的无状态功能组件重构为一个类。但是,这样做的时候,我总是收到错误消息,好像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(
我不明白 如何调试/修复此问题?
如果我发布的代码与某种原因无关,则此应用程序的完整代码在此处。
谢谢!
哦…
import { React, Component } from 'react';
需要是
import React, { Component } from 'react';
:)