I am new to React. Want to develop an application using small components in separate files and import them into App.js
I tried, but could not understand what I was doing wrong.
Here is my html:
<!DOCTYPE html> <html> <head> <title>App</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <script src="https://unpkg.com/ react@15.3.2 /dist/react.js"></script> <script src="https://unpkg.com/ react-dom@15.3.2 /dist/react-dom.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script> </head> <body> <script type="text/babel" src="js/App.js"></script> </body> </html>
This is my App.js: (from js / directory)
import MyComp from 'components/MyComp'; class App extends React.Component { render() { return ( <MyComp /> ) } } ReactDOM.render( <App />, document.body );
And this is my MyComp.js (from the js / components / directory)
class MyComp extends React.Component{ render() { return ( <div> Hello World! </div> ) } } export default MyComp;
If I try this way, I donβt see anything. If I create the MyComp class in App.js, it works like a charm.
Any suggestion what am I doing wrong?
source share