I have written a simple ReactJS code in which I am trying to call render() function from inside of the Store class but I am getting error. If I am calling ReactDOM.render() function from outside of the Store class then the this.state.data is not accessible outside of the Store class. So please tell what should I do?
Code:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';
class Store extends React.Component {
constructor(props) {
super(props);
this.state = {
data:
[
{
name: 'First...',
id: 1
},
{
name: 'Second...',
id: 2
},
{
name: 'Third...',
id: 3
}
]
}
};
render(
<App storeData={this.state.data} />,
document.getElementById('app')
);
}
Error:
ERROR in ./main.js
Module build failed: SyntaxError: C:/Users/username/Desktop/fluxExample/main.js
: Unexpected token (31:2)
29 |
30 | render(
> 31 | <App storeData={this.state.data} />,
| ^
32 | document.getElementById('app')
33 | );
34 | }
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-serve
r ./main.js
webpack: Failed to compile.