Commit 61b123df authored by Jurie Horneman's avatar Jurie Horneman Committed by Dan Abramov
Browse files

Added info on using global variables. (#976)

* Added info on using global variables.

See issue #972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
parent 8cf45e1f
No related merge requests found
Showing with 17 additions and 0 deletions
+17 -0
......@@ -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)
......@@ -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:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment