Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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 未捕获(承诺中)类型错误:无法读取属性';createElement';未定义的(…;)_Javascript_Reactjs - Fatal编程技术网

Javascript 未捕获(承诺中)类型错误:无法读取属性';createElement';未定义的(…;)

Javascript 未捕获(承诺中)类型错误:无法读取属性';createElement';未定义的(…;),javascript,reactjs,Javascript,Reactjs,我需要将无状态功能组件重构为一个类。当我这样做的时候,我不断得到一个错误,它看起来像是React本身没有定义 import React from 'react'; import { Cell } from 'fixed-data-table'; const DataCell = ({rowIndex, columnKey, data, onMessageClicked, ...props}) => { return ( <Cell {...props} onClick=

我需要将无状态功能组件重构为一个类。当我这样做的时候,我不断得到一个错误,它看起来像是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;
从“React”导入React;
从“固定数据表”导入{Cell};
const DataCell=({rowIndex,columnKey,data,onMessageClicked,…props})=>{
返回(
{data[rowIndex][columnKey]}
);
};
导出默认数据单元;

从'React'导入{React,Component};
从“固定数据表”导入{Cell};
类DataCell扩展组件{
onCellClicked(){
this.props.onMessageClicked(this.props.data[this.props.rowIndex].Id);
}
render(){
const{rowIndex,columnKey,data,…props}=this.props;
返回(
{data[rowIndex][columnKey]}
);
}
}
导出默认数据单元;
bundle.js:43248未捕获(承诺中)类型错误:无法读取未定义(…)的属性“createElement”

当我走到那条线时,我看到

return\u react.react.createElement(

我不明白。我如何调试/修复它

我这个应用程序的完整代码是为了防止我发布的代码不相关

谢谢!

从“React”导入{React,Component};

需要

从“React”导入React,{Component};


:)

OP自己回答了这个问题,但没有理由,所以原因如下! {直接引用自“}

是不正确的,应该是

import React, { Component } from 'react';
没有名为React的命名导出。这令人困惑,因为React是一个CommonJS模块,并且由于您使用ES6导入,Babel尝试映射语义,但它们并不完全匹配。{Component}实际上从React本身获取组件,因此您可以:

import React from 'react'

如果比较容易混淆,请使用
React.Component

对于我在TypeScript中的解决方案是:

import * as React from 'react';

今天仍然很有用,这有点让人头疼。谢谢!我使用的是Typescript 2.1.5版本,这对我很有帮助。我认为tsconfig.json中存在问题。也许
types:['node']
也会有帮助。
import React from 'react'
import * as React from 'react';