Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  178] [ 2]  / answers: 1 / hits: 17374  / 8 Years ago, sat, may 21, 2016, 12:00:00

I needed to refactor my stateless functional component to a class. When I did so though, I keep getting an error where it looks like React itself is undefined.



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;


to



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(…)



and when I go to that line I see



return _react.React.createElement(



I don't get it. How do I debug/fix this?



My full code for this app is here in case the code I'm posting is not related somehow.



Thanks!


More From » reactjs

 Answers
10

Oh...



import { React, Component } from 'react';



needs to be



import React, { Component } from 'react';



:)


[#62081] Thursday, May 19, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gideonb

Total Points: 187
Total Questions: 101
Total Answers: 86

Location: North Korea
Member since Mon, Feb 27, 2023
1 Year ago
;