The specified file was not found on this website. Please check the URL for mistakes and try again.
29 |
Why am I seeing this?
30 |
This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
2 |
3 | Below you will find some information on how to perform common tasks.
4 | You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md).
5 |
6 | ## Table of Contents
7 |
8 | - [Updating to New Releases](#updating-to-new-releases)
9 | - [Sending Feedback](#sending-feedback)
10 | - [Folder Structure](#folder-structure)
11 | - [Available Scripts](#available-scripts)
12 | - [npm start](#npm-start)
13 | - [npm test](#npm-test)
14 | - [npm run build](#npm-run-build)
15 | - [npm run eject](#npm-run-eject)
16 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
17 | - [Installing a Dependency](#installing-a-dependency)
18 | - [Importing a Component](#importing-a-component)
19 | - [Adding a Stylesheet](#adding-a-stylesheet)
20 | - [Post-Processing CSS](#post-processing-css)
21 | - [Adding Images and Fonts](#adding-images-and-fonts)
22 | - [Using the `public` Folder](#using-the-public-folder)
23 | - [Adding Bootstrap](#adding-bootstrap)
24 | - [Adding Flow](#adding-flow)
25 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
26 | - [Can I Use Decorators?](#can-i-use-decorators)
27 | - [Integrating with a Node Backend](#integrating-with-a-node-backend)
28 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
29 | - [Using HTTPS in Development](#using-https-in-development)
30 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
31 | - [Running Tests](#running-tests)
32 | - [Filename Conventions](#filename-conventions)
33 | - [Command Line Interface](#command-line-interface)
34 | - [Version Control Integration](#version-control-integration)
35 | - [Writing Tests](#writing-tests)
36 | - [Testing Components](#testing-components)
37 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries)
38 | - [Initializing Test Environment](#initializing-test-environment)
39 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests)
40 | - [Coverage Reporting](#coverage-reporting)
41 | - [Continuous Integration](#continuous-integration)
42 | - [Disabling jsdom](#disabling-jsdom)
43 | - [Experimental Snapshot Testing](#experimental-snapshot-testing)
44 | - [Deployment](#deployment)
45 | - [Building for Relative Paths](#building-for-relative-paths)
46 | - [GitHub Pages](#github-pages)
47 | - [Heroku](#heroku)
48 | - [Modulus](#modulus)
49 | - [Now](#now)
50 | - [Surge](#surge)
51 | - [Something Missing?](#something-missing)
52 |
53 | ## Updating to New Releases
54 |
55 | Create React App is divided into two packages:
56 |
57 | * `create-react-app` is a global command-line utility that you use to create new projects.
58 | * `react-scripts` is a development dependency in the generated projects (including this one).
59 |
60 | You almost never need to update `create-react-app` itself: it’s delegates all the setup to `react-scripts`.
61 |
62 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically.
63 |
64 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions.
65 |
66 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes.
67 |
68 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
69 |
70 | ## Sending Feedback
71 |
72 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
73 |
74 | ## Folder Structure
75 |
76 | After creation, your project should look like this:
77 |
78 | ```
79 | my-app/
80 | README.md
81 | node_modules/
82 | package.json
83 | public/
84 | index.html
85 | favicon.ico
86 | src/
87 | App.css
88 | App.js
89 | App.test.js
90 | index.css
91 | index.js
92 | logo.svg
93 | ```
94 |
95 | For the project to build, **these files must exist with exact filenames**:
96 |
97 | * `public/index.html` is the page template;
98 | * `src/index.js` is the JavaScript entry point.
99 |
100 | You can delete or rename the other files.
101 |
102 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
103 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them.
104 |
105 | Only files inside `public` can be used from `public/index.html`.
106 | Read instructions below for using assets from JavaScript and HTML.
107 |
108 | You can, however, create more top-level directories.
109 | They will not be included in the production build so you can use them for things like documentation.
110 |
111 | ## Available Scripts
112 |
113 | In the project directory, you can run:
114 |
115 | ### `npm start`
116 |
117 | Runs the app in the development mode.
118 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
119 |
120 | The page will reload if you make edits.
121 | You will also see any lint errors in the console.
122 |
123 | ### `npm test`
124 |
125 | Launches the test runner in the interactive watch mode.
126 | See the section about [running tests](#running-tests) for more information.
127 |
128 | ### `npm run build`
129 |
130 | Builds the app for production to the `build` folder.
131 | It correctly bundles React in production mode and optimizes the build for the best performance.
132 |
133 | The build is minified and the filenames include the hashes.
134 | Your app is ready to be deployed!
135 |
136 | ### `npm run eject`
137 |
138 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
139 |
140 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
141 |
142 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
143 |
144 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
145 |
146 | ## Displaying Lint Output in the Editor
147 |
148 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
149 |
150 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
151 |
152 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do.
153 |
154 | You would need to install an ESLint plugin for your editor first.
155 |
156 | >**A note for Atom `linter-eslint` users**
157 |
158 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked:
159 |
160 | >
161 |
162 | Then add this block to the `package.json` file of your project:
163 |
164 | ```js
165 | {
166 | // ...
167 | "eslintConfig": {
168 | "extends": "react-app"
169 | }
170 | }
171 | ```
172 |
173 | Finally, you will need to install some packages *globally*:
174 |
175 | ```sh
176 | npm install -g eslint-config-react-app@0.2.1 eslint@3.5.0 babel-eslint@6.1.2 eslint-plugin-react@6.3.0 eslint-plugin-import@1.12.0 eslint-plugin-jsx-a11y@2.2.2 eslint-plugin-flowtype@2.18.1
177 | ```
178 |
179 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months.
180 |
181 | ## Installing a Dependency
182 |
183 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`:
184 |
185 | ```
186 | npm install --save
187 | ```
188 |
189 | ## Importing a Component
190 |
191 | This project setup supports ES6 modules thanks to Babel.
192 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead.
193 |
194 | For example:
195 |
196 | ### `Button.js`
197 |
198 | ```js
199 | import React, { Component } from 'react';
200 |
201 | class Button extends Component {
202 | render() {
203 | // ...
204 | }
205 | }
206 |
207 | export default Button; // Don’t forget to use export default!
208 | ```
209 |
210 | ### `DangerButton.js`
211 |
212 |
213 | ```js
214 | import React, { Component } from 'react';
215 | import Button from './Button'; // Import a component from another file
216 |
217 | class DangerButton extends Component {
218 | render() {
219 | return ;
220 | }
221 | }
222 |
223 | export default DangerButton;
224 | ```
225 |
226 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes.
227 |
228 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`.
229 |
230 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like.
231 |
232 | Learn more about ES6 modules:
233 |
234 | * [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281)
235 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
236 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
237 |
238 | ## Adding a Stylesheet
239 |
240 | This project setup uses [Webpack](https://webpack.github.io/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**:
241 |
242 | ### `Button.css`
243 |
244 | ```css
245 | .Button {
246 | padding: 20px;
247 | }
248 | ```
249 |
250 | ### `Button.js`
251 |
252 | ```js
253 | import React, { Component } from 'react';
254 | import './Button.css'; // Tell Webpack that Button.js uses these styles
255 |
256 | class Button extends Component {
257 | render() {
258 | // You can use them as regular CSS styles
259 | return ;
260 | }
261 | }
262 | ```
263 |
264 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack.
265 |
266 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
267 |
268 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool.
269 |
270 | ## Post-Processing CSS
271 |
272 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it.
273 |
274 | For example, this:
275 |
276 | ```css
277 | .App {
278 | display: flex;
279 | flex-direction: row;
280 | align-items: center;
281 | }
282 | ```
283 |
284 | becomes this:
285 |
286 | ```css
287 | .App {
288 | display: -webkit-box;
289 | display: -ms-flexbox;
290 | display: flex;
291 | -webkit-box-orient: horizontal;
292 | -webkit-box-direction: normal;
293 | -ms-flex-direction: row;
294 | flex-direction: row;
295 | -webkit-box-align: center;
296 | -ms-flex-align: center;
297 | align-items: center;
298 | }
299 | ```
300 |
301 | There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
302 |
303 | ## Adding Images and Fonts
304 |
305 | With Webpack, using static assets like images and fonts works similarly to CSS.
306 |
307 | You can **`import` an image right in a JavaScript module**. This tells Webpack to include that image in the bundle. Unlike CSS imports, importing an image or a font gives you a string value. This value is the final image path you can reference in your code.
308 |
309 | Here is an example:
310 |
311 | ```js
312 | import React from 'react';
313 | import logo from './logo.png'; // Tell Webpack this JS file uses this image
314 |
315 | console.log(logo); // /logo.84287d09.png
316 |
317 | function Header() {
318 | // Import result is the URL of your image
319 | return ;
320 | }
321 |
322 | export default function Header;
323 | ```
324 |
325 | This ensures that when the project is built, webpack will correctly move the images into the build folder, and provide us with correct paths.
326 |
327 | This works in CSS too:
328 |
329 | ```css
330 | .Logo {
331 | background-image: url(./logo.png);
332 | }
333 | ```
334 |
335 | Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets.
336 |
337 | Please be advised that this is also a custom feature of Webpack.
338 |
339 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).
340 | An alternative way of handling static assets is described in the next section.
341 |
342 | ## Using the `public` Folder
343 |
344 | >Note: this feature is available with `react-scripts@0.5.0` and higher.
345 |
346 | Normally we encourage you to `import` assets in JavaScript files as described above. This mechanism provides a number of benefits:
347 |
348 | * Scripts and stylesheets get minified and bundled together to avoid extra network requests.
349 | * Missing files cause compilation errors instead of 404 errors for your users.
350 | * Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.
351 |
352 | However there is an **escape hatch** that you can use to add an asset outside of the module system.
353 |
354 | If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`.
355 |
356 | Inside `index.html`, you can use it like this:
357 |
358 | ```html
359 |
360 | ```
361 |
362 | Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build.
363 |
364 | When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL.
365 |
366 | In JavaScript code, you can use `process.env.PUBLIC_URL` for similar purposes:
367 |
368 | ```js
369 | render() {
370 | // Note: this is an escape hatch and should be used sparingly!
371 | // Normally we recommend using `import` for getting asset URLs
372 | // as described in “Adding Images and Fonts” above this section.
373 | return ;
374 | }
375 | ```
376 |
377 | Keep in mind the downsides of this approach:
378 |
379 | * None of the files in `public` folder get post-processed or minified.
380 | * Missing files will not be called at compilation time, and will cause 404 errors for your users.
381 | * Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change.
382 |
383 | However, it can be handy for referencing assets like [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest) from HTML, or including small scripts like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code.
384 |
385 | ## Adding Bootstrap
386 |
387 | You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps:
388 |
389 | Install React Bootstrap and Bootstrap from NPM. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well:
390 |
391 | ```
392 | npm install react-bootstrap --save
393 | npm install bootstrap@3 --save
394 | ```
395 |
396 | Import Bootstrap CSS and optionally Bootstrap theme CSS in the ```src/index.js``` file:
397 |
398 | ```js
399 | import 'bootstrap/dist/css/bootstrap.css';
400 | import 'bootstrap/dist/css/bootstrap-theme.css';
401 | ```
402 |
403 | Import required React Bootstrap components within ```src/App.js``` file or your custom component files:
404 |
405 | ```js
406 | import { Navbar, Jumbotron, Button } from 'react-bootstrap';
407 | ```
408 |
409 | Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example [`App.js`](https://gist.githubusercontent.com/gaearon/85d8c067f6af1e56277c82d19fd4da7b/raw/6158dd991b67284e9fc8d70b9d973efe87659d72/App.js) redone using React Bootstrap.
410 |
411 | ## Adding Flow
412 |
413 | Flow typing is currently [not supported out of the box](https://github.com/facebookincubator/create-react-app/issues/72) with the default `.flowconfig` generated by Flow. If you run it, you might get errors like this:
414 |
415 | ```js
416 | node_modules/fbjs/lib/Deferred.js.flow:60
417 | 60: Promise.prototype.done.apply(this._promise, arguments);
418 | ^^^^ property `done`. Property not found in
419 | 495: declare class Promise<+R> {
420 | ^ Promise. See lib: /private/tmp/flow/flowlib_34952d31/core.js:495
421 |
422 | node_modules/fbjs/lib/shallowEqual.js.flow:29
423 | 29: return x !== 0 || 1 / (x: $FlowIssue) === 1 / (y: $FlowIssue);
424 | ^^^^^^^^^^ identifier `$FlowIssue`. Could not resolve name
425 | ```
426 |
427 | To fix this, change your `.flowconfig` to look like this:
428 |
429 | ```ini
430 | [ignore]
431 | /node_modules/fbjs/.*
432 | ```
433 |
434 | Re-run flow, and you shouldn’t get any extra issues.
435 |
436 | ## Adding Custom Environment Variables
437 |
438 | >Note: this feature is available with `react-scripts@0.2.3` and higher.
439 |
440 | Your project can consume variables declared in your environment as if they were declared locally in your JS files. By
441 | default you will have `NODE_ENV` defined for you, and any other environment variables starting with
442 | `REACT_APP_`. These environment variables will be defined for you on `process.env`. For example, having an environment
443 | variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`, in addition
444 | to `process.env.NODE_ENV`.
445 |
446 | These environment variables can be useful for displaying information conditionally based on where the project is
447 | deployed or consuming sensitive data that lives outside of version control.
448 |
449 | First, you need to have environment variables defined. For example, let’s say you wanted to consume a secret defined
450 | in the environment inside a `