Siva
Siva

Reputation: 1276

React.js importing and using Components

I was following Facebook's tutorial on React.js and for the sake of the tutorial, they made their example all on one page.

I was wondering how I separate my components into a separate file and import them into my main app. Something like the following.

/components
------>component1.js
------>component2.js
------>component3.js
/css
app.js
index.html

From the examples online, some require components in and others import them.

What is the best way to do this currently and is there a good boilerplate/example I can follow?

Upvotes: 1

Views: 975

Answers (1)

andyrandy
andyrandy

Reputation: 73984

"import" is from JavaScript ES6, i highly recommend using it - with babel.

You will find many boilerplate projects with a simple google search for "react es6 boilerplate", for example: https://github.com/vasanthk/react-es6-webpack-boilerplate

There is a simple example about how to use components in another boilerplate: https://github.com/lalitkapoor/webpack-es6-react-boilerplate/tree/master/public/js

Upvotes: 4

Related Questions