|
1 | 1 | --- |
2 | | -id: installation |
3 | | -title: Installation |
4 | | -permalink: docs/installation.html |
5 | | -redirect_from: |
6 | | - - "download.html" |
7 | | - - "downloads.html" |
8 | | - - "docs/tooling-integration.html" |
9 | | - - "docs/package-management.html" |
10 | | - - "docs/language-tooling.html" |
11 | | - - "docs/environments.html" |
12 | | -next: hello-world.html |
| 2 | +id: add-react-to-an-existing-app |
| 3 | +title: Add React to an Existing Application |
| 4 | +permalink: docs/add-react-to-an-existing-app.html |
| 5 | +prev: add-react-to-a-new-app.html |
| 6 | +next: cdn-links.html |
13 | 7 | --- |
14 | 8 |
|
15 | | -React is flexible and can be used in a variety of projects. You can create new apps with it, but you can also gradually introduce it into an existing codebase without doing a rewrite. |
16 | | - |
17 | | -Here are a couple of ways to get started: |
18 | | - |
19 | | -* [Try React](#trying-out-react) |
20 | | -* [Create a New App](#creating-a-new-application) |
21 | | -* [Add React to an Existing App](#adding-react-to-an-existing-application) |
22 | | - |
23 | | -## Trying Out React |
24 | | - |
25 | | -If you're just interested in playing around with React, you can use CodePen. Try starting from [this Hello World example code](http://codepen.io/gaearon/pen/rrpgNB?editors=0010). You don't need to install anything; you can just modify the code and see if it works. |
26 | | - |
27 | | -If you prefer to use your own text editor, you can also [download this HTML file](https://raw.githubusercontent.com/reactjs/reactjs.org/master/static/html/single-file-example.html), edit it, and open it from the local filesystem in your browser. It does a slow runtime code transformation, so don't use it in production. |
28 | | - |
29 | | -If you want to use it for a full application, there are two popular ways to get started with React: using Create React App, or adding it to an existing application. |
30 | | - |
31 | | -## Creating a New Application |
32 | | - |
33 | | -[Create React App](http://github.com/facebookincubator/create-react-app) is the best way to start building a new React single page application. It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production. You’ll need to have Node >= 6 on your machine. |
34 | | - |
35 | | -```bash |
36 | | -npm install -g create-react-app |
37 | | -create-react-app my-app |
38 | | - |
39 | | -cd my-app |
40 | | -npm start |
41 | | -``` |
42 | | - |
43 | | -If you have npm 5.2.0+ installed, you may use [npx](https://www.npmjs.com/package/npx) instead. |
44 | | - |
45 | | -```bash |
46 | | -npx create-react-app my-app |
47 | | - |
48 | | -cd my-app |
49 | | -npm start |
50 | | -``` |
51 | | - |
52 | | -Create React App doesn't handle backend logic or databases; it just creates a frontend build pipeline, so you can use it with any backend you want. It uses build tools like [Babel](http://babeljs.io/) and [webpack](https://webpack.js.org/) under the hood, but works with zero configuration. |
53 | | - |
54 | | -When you're ready to deploy to production, running `npm run build` will create an optimized build of your app in the `build` folder. You can learn more about Create React App [from its README](https://github.com/facebookincubator/create-react-app#create-react-app-) and the [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#table-of-contents). |
55 | | - |
56 | | -## Adding React to an Existing Application |
57 | | - |
58 | 9 | You don't need to rewrite your app to start using React. |
59 | 10 |
|
60 | 11 | We recommend adding React to a small part of your application, such as an individual widget, so you can see if it works well for your use case. |
@@ -134,34 +85,4 @@ Learn [how to tell if your website is serving the right version of React](/docs/ |
134 | 85 |
|
135 | 86 | ### Using a CDN |
136 | 87 |
|
137 | | -If you don't want to use npm to manage client packages, the `react` and `react-dom` npm packages also provide single-file distributions in `umd` folders, which are hosted on a CDN: |
138 | | - |
139 | | -```html |
140 | | -<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> |
141 | | -<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> |
142 | | -``` |
143 | | - |
144 | | -The versions above are only meant for development, and are not suitable for production. Minified and optimized production versions of React are available at: |
145 | | - |
146 | | -```html |
147 | | -<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script> |
148 | | -<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> |
149 | | -``` |
150 | | - |
151 | | -To load a specific version of `react` and `react-dom`, replace `16` with the version number. |
152 | | - |
153 | | -If you use Bower, React is available via the `react` package. |
154 | | - |
155 | | -#### Why the `crossorigin` Attribute? |
156 | | - |
157 | | -If you serve React from a CDN, we recommend to keep the [`crossorigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) attribute set: |
158 | | - |
159 | | -```html |
160 | | -<script crossorigin src="..."></script> |
161 | | -``` |
162 | | - |
163 | | -We also recommend to verify that the CDN you are using sets the `Access-Control-Allow-Origin: *` HTTP header: |
164 | | - |
165 | | - |
166 | | - |
167 | | -This enables a better [error handling experience](/blog/2017/07/26/error-handling-in-react-16.html) in React 16 and later. |
| 88 | +If you don't want to use npm to manage client packages, the `react` and `react-dom` npm packages also provide single-file distributions in `umd` folders. See the [CDN](/docs/cdn-links.html) page for links. |
0 commit comments