Skip to content

Commit cd2843d

Browse files
committed
fix(readme) prioritize install generator, don't suggest manually inserting requires
1 parent c5e884c commit cd2843d

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

README.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Next, run the installation script.
3939
rails g react:install
4040
```
4141

42-
This will require `react.js`, `react_ujs.js`, and a `components.js` manifest file in application.js, and create a directory named `app/assets/javascripts/components` for you to store React components in.
42+
This will:
43+
- create a `components.js` manifest file and a `app/assets/javascripts/components/` directory, where you will put your compoennts
44+
- require `react.js`, `react_ujs.js`, and `components.js` in `application.js`
4345

4446
## Usage
4547

@@ -67,15 +69,7 @@ MyApp::Application.configure do
6769
end
6870
```
6971

70-
Then, you can include the requested build in your front-end by restarting your Rails server and adding `react` to your manifest:
71-
72-
```js
73-
// app/assets/javascripts/application.js
74-
75-
//= require react
76-
```
77-
78-
It will provide the build of React.js which was specified by the configurations.
72+
After restarting your Rails server, `//= require react` will provide the build of React.js which was specified by the configurations.
7973

8074
In a pinch, you can also provide your own copies of React.js and JSXTransformer. Just add `react.js` or `JSXTransformer.js` (case-sensitive) files to `app/vendor/assets/javascripts/react/` and restart your development server. If you need different versions of React in different environments, put them in directories that match `config.react.variant`. For example, if you set `config.react.variant = :development`, you could put a copy of `react.js` in `/vendor/assets/react/development/`.
8175

@@ -102,15 +96,7 @@ Component = React.createClass
10296

10397
### Rendering & mounting
10498

105-
`react-rails` includes a view helper (`react_component`) and an unobtrusive JavaScript (UJS) driver which work together to put React components on the page. You should require the UJS driver in your manifest after `react` (and after `turbolinks` if you use [Turbolinks](https://github.com/rails/turbolinks))
106-
107-
```js
108-
// app/assets/javascripts/application.js
109-
110-
//= require turbolinks
111-
//= require react
112-
//= require react_ujs
113-
```
99+
`react-rails` includes a view helper (`react_component`) and an unobtrusive JavaScript driver (`react_ujs`) which work together to put React components on the page. You should require the UJS driver in your manifest after `react` (and after `turbolinks` if you use [Turbolinks](https://github.com/rails/turbolinks))
114100

115101
The __view helper__ puts a `div` on the page with the requested component class & props. For example:
116102

@@ -138,7 +124,6 @@ react_component(component_class_name, props={}, html_options={})
138124
- `**other` Any other arguments (eg `class:`, `id:`) are passed through to [`content_tag`](http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
139125

140126

141-
142127
### Server rendering
143128

144129
To render components on the server, pass `prerender: true` to `react_component`:
@@ -155,13 +140,7 @@ _(It will be also be mounted by the UJS on page load.)_
155140

156141
There are some requirements for this to work:
157142

158-
- `react-rails` must load your code. By convention, it looks for a `assets/javascripts/components.js` file through the asset pipeline and loads that. This file must include your components _and_ their dependencies (eg, Underscore.js). For example:
159-
160-
```js
161-
// app/assets/javascripts/components.js
162-
//= require_tree ./components
163-
// ^^ loads all files in `app/assets/javascripts/components/`
164-
```
143+
- `react-rails` must load your code. By convention, it uses `components.js`, which was created by the install task. This file must include your components _and_ their dependencies (eg, Underscore.js).
165144
- Your components must be accessible in the global scope. If you are using `.js.jsx.coffee` files then the wrapper function needs to be taken into account:
166145

167146
```coffee

0 commit comments

Comments
 (0)