Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added info on using global variables. #976

Merged
merged 5 commits into from
Nov 20, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved new section.
  • Loading branch information
jhorneman committed Oct 28, 2016
commit b1030f26d52a8fbc53ef386f998aec1e8bba9bde
30 changes: 15 additions & 15 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ 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)
- [Can I Use Decorators?](#can-i-use-decorators)
- [Using Global Variables defined elsewhere](#using-global-variables-defined-elsewhere)
- [Integrating with a Node Backend](#integrating-with-a-node-backend)
- [Proxying API Requests in Development](#proxying-api-requests-in-development)
- [Using HTTPS in Development](#using-https-in-development)
Expand Down Expand Up @@ -384,6 +384,20 @@ 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.

## Using Global Variables defined elsewhere

When you include a script in the HTML file that defines global variables, and you then try to use one of these variables in code managed by Create React App, ESLint 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, e.g.:

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

This also makes it obvious you are using a global variable.

Alternatively, you can force ESLint to ignore any line with `// eslint-disable-line`.

## 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 Expand Up @@ -543,20 +557,6 @@ Please refer to these two threads for reference:

Create React App will add decorator support when the specification advances to a stable stage.

## Using Global Variables defined elsewhere

When you include a script in the HTML file that defines global variables, and you then try to use one of these variables in code managed by Create React App, ESLint 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, e.g.:

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

This also makes it obvious you are using a global variable.

You can also force ESLint to ignore any line with `// eslint-disable-line`.

## Integrating with a Node Backend

Check out [this tutorial](https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/) for instructions on integrating an app with a Node backend running on another port, and using `fetch()` to access it. You can find the companion GitHub repository [here](https://github.com/fullstackreact/food-lookup-demo).
Expand Down