I am trying to import multiple component which is in one single jsx file in the main js file
This question has been already answered but without example here How to import and export components using React + ES6 + webpack?
My code is as below
App3.jsx file
import React from '../node_modules/react';
export default class App2 extends React.Component {
render() {
var i = 1;
var myStyle = {
fontSize: 25,
color: '#FF0000'
}
return (
<div>
<h1>Header</h1>
<h2>Content</h2>
<p data-myattribute = "somevalue">This is the content!!!</p>
<h1>{1+1}</h1>
<h1>{i = 1 ? 'True!' : 'False'}</h1>
<h1 style = {myStyle}>Header</h1>
{ /*gsadjshds */ }
</div>
);
}
}
export default class App3 extends React.Component {
render() {
return (
<div>
<Header/>
<Content/>
</div>
);
}
}
export default class Header extends React.Component {
render() {
return (
<div>
<h1>Header</h1>
</div>
);
}
}
export default class Content extends React.Component {
render() {
return (
<div>
<h2>Content</h2>
<p>The content text!!!</p>
</div>
);
}
}
And main.js file as below
import React from './node_modules/react';
import ReactDOM from './node_modules/react-dom';
import App from './js/App.jsx';
import App1 from './js/App1.jsx';
import {App2, App3} from './js/App3.jsx';
ReactDOM.render(<App />, document.getElementById('app'));
ReactDOM.render(<App1 />, document.getElementById('app1'));
ReactDOM.render(<App2 />, document.getElementById('app2'));
ReactDOM.render(<App3 />, document.getElementById('app3'));
But i am getting below errors
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Your help will be appreciated
{i = 1 ? 'True!' : 'False'}
` this is probably wrong, unless you really want to assign `1` to `i`. ` – JensG Jun 12 '16 at 11:41