I play with React and ES6 using babel and webpack . I want to create several components in different files, import them into one file and link them to webpack
Let's say I have several such components:
my-navbar.jsx
import React from 'react'; import Navbar from 'react-bootstrap/lib/Navbar'; export class MyNavbar extends React.Component { render(){ return ( <Navbar className="navbar-dark" fluid> ... </Navbar> ); } }
main page.jsx
import React from 'react'; import ReactDOM from 'react-dom'; import MyNavbar from './comp/my-navbar.jsx'; export class MyPage extends React.Component{ render(){ return( <MyNavbar /> ... ); } } ReactDOM.render( <MyPage />, document.getElementById('container') );
Using webpack and following their tutorial, I have main.js :
import MyPage from './main-page.jsx';
After creating the project and starting it, I get the following error in the browser console:
Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `MyPage`.
What am I doing wrong? How to import and export my components?
ecmascript-6 reactjs webpack
itaied Nov 27 '15 at 11:16 2015-11-27 11:16
source share