Skip to content

Commit

Permalink
Added info on using global variables. (facebook#976)
Browse files Browse the repository at this point in the history
* Added info on using global variables.

See issue facebook#972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
  • Loading branch information
jhorneman authored and jarlef committed Nov 28, 2016
1 parent b00b262 commit 7a9dc58
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
- [Post-Processing CSS](#post-processing-css)
- [Adding Images and Fonts](#adding-images-and-fonts)
- [Using the `public` Folder](#using-the-public-folder)
- [Using Global Variables Defined Elsewhere](#using-global-variables-defined-elsewhere)
- [Adding Bootstrap](#adding-bootstrap)
- [Adding Flow](#adding-flow)
- [Adding Custom Environment Variables](#adding-custom-environment-variables)
Expand Down Expand Up @@ -384,6 +385,22 @@ Keep in mind the downsides of this approach:

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.

Note that if you add a `<script>` that declares global variables, you also need to read the next section on using them.

## Using Global Variables Defined Elsewhere

When you include a script in the HTML file that defines global variables and try to use one of these variables in the code, the linter will complain because it cannot see the definition of the variable.

You can avoid this by reading the global variable explicitly from the `window` object, for example:

```js
const $ = window.$;
```

This makes it obvious you are using a global variable intentionally rather than because of a typo.

Alternatively, you can force the linter to ignore any line by adding `// eslint-disable-line` after it.

## Adding Bootstrap

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:
Expand Down

0 comments on commit 7a9dc58

Please sign in to comment.