You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gem version 2.4.x onwards and master will no longer have React Addons.
9
+
React-Rails makes it easy to use [React](http://facebook.github.io/react/)and [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) in your Ruby on Rails (3.2 to 5+) application.
10
10
11
-
If you need to make changes for the prebundled react, see the migration docs here:
`react-rails` makes it easy to use [React](http://facebook.github.io/react/) and [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) in your Ruby on Rails (3.2+) application. Learn more:
11
+
Automatic Server-side Rendering (SSR) with **Webpacker** 3+ down to 1.1 support!
17
12
13
+
## Learn more
18
14
- React's [Getting Started guide](https://facebook.github.io/react/docs/getting-started.html)
19
-
- Use React & JSX [with Webpacker](#use-with-webpacker) or [with the asset pipeline](#use-with-asset-pipeline)
20
-
- Rendering [components in views](#view-helper) or [in controller actions](#controller-actions)
21
-
-[Server-side rendering](#server-side-rendering)
15
+
- Use React & JSX [with Webpacker](#get-started-with-webpacker)
16
+
- or [with the asset pipeline](#use-with-asset-pipeline)
17
+
-[Rendering components in views](#view-helper)
18
+
- or [Render directly in controller actions](#controller-actions)
22
19
-[Generating components](#component-generator) in various formats
23
-
-[`ReactRailsUJS`](#ujs) for mounting and unmounting components
@@ -74,8 +70,6 @@ The component name tells `react-rails` where to load the component. For example:
74
70
75
71
This way, you can access top-level, default, or named exports.
76
72
77
-
If `require` fails, `react-rails` falls back to the global namespace approach described in [Use with Asset Pipeline](#use-with-asset-pipeline).
78
-
79
73
The `require.context` inserted into `packs/application.js` is used to load components. If you want to load components from a different directory, override it by calling `ReactRailsUJS.useContext`:
80
74
81
75
```js
@@ -85,7 +79,12 @@ var ReactRailsUJS = require("react_ujs")
85
79
ReactRailsUJS.useContext(myCustomContext)
86
80
```
87
81
88
-
### Gotcha: Capitalization
82
+
If `require` fails to find your component, [`ReactRailsUJS`](#ujs) falls back to the global namespace, described in [Use with Asset Pipeline](#use-with-asset-pipeline).
83
+
84
+
### File naming
85
+
86
+
React-Rails supports plenty of file extensions such as: .js, .jsx.js, .js.jsx, .es6.js, .coffee, etcetera!
87
+
Sometimes this will cause a stumble when searching for filenames.
89
88
90
89
Component File Name | `react_component` call
91
90
-----|-----
@@ -97,7 +96,7 @@ Component File Name | `react_component` call
97
96
98
97
## Use with Asset Pipeline
99
98
100
-
`react-rails` provides React.js & a UJS driver to the Rails asset pipeline. Get started by installing:
99
+
`react-rails` provides a pre-bundled React.js & a UJS driver to the Rails asset pipeline. Get started by installing:
101
100
102
101
```
103
102
$ rails g react:install
@@ -113,7 +112,7 @@ This will:
113
112
114
113
Now, you can create React components in `.jsx` files:
115
114
116
-
```js
115
+
```JSX
117
116
// app/assets/javascripts/components/post.jsx
118
117
119
118
window.Post=createReactClass({
@@ -171,7 +170,7 @@ MyApp::Application.configure do
171
170
end
172
171
```
173
172
174
-
Be sure to restart your Rails server after changing these files. See [VERSIONS.md](https://github.com/reactjs/react-rails/blob/master/VERSIONS.md) to learn which version of React.js is included with your `react-rails` version.
173
+
Be sure to restart your Rails server after changing these files. See [VERSIONS.md](https://github.com/reactjs/react-rails/blob/master/VERSIONS.md) to learn which version of React.js is included with your `react-rails` version. In some edge cases you may need to bust the sprockets cache with `rake tmp:clear`
175
174
176
175
177
176
## View Helper
@@ -402,7 +401,7 @@ rails g react:component Post title:string published:bool published_by:instanceOf
402
401
403
402
would generate:
404
403
405
-
```js
404
+
```JSX
406
405
var Post =createReactClass({
407
406
propTypes: {
408
407
title:PropTypes.string,
@@ -480,29 +479,50 @@ You can also specify this option in `react_component`:
- [react\_on\_rails Gem](https://github.com/shakacode/react_on_rails): Integration of React with Rails utilizing Webpack, Babel, React, Redux, React-Router.
486
-
- [Ruby Hyperloop](http://ruby-hyperloop.org/): Use Ruby to build reactive user interfaces with React.
487
-
- [react-rails-hot-loader](https://github.com/rmosolgo/react-rails-hot-loader) is a simple live-reloader for `react-rails`.
488
-
- [react-rails-benchmark_renderer](https://github.com/pboling/react-rails-benchmark_renderer) adds performance instrumentation to server rendering.
489
-
- [The Free React on Rails Course](https://learnetto.com/users/hrishio/courses/the-free-react-on-rails-5-course) A free video course which teaches the basics of React and how to get started using it in Rails with `react-rails`.
484
+
### 2.3 to 2.4
490
485
491
-
## Development
486
+
React-Rails 2.4.x uses React 16+ which no longer has React Addons. Therefore the pre-bundled version of react no longer has an addons version, if you need addons still, there is the 2.3.1+ version of the gem that still has addons.
492
487
493
-
- Run tests with `rake test` or `appraisal rake test`
488
+
If you need to make changes for the prebundled react, see the migration docs here:
We have a [Code of Conduct]() that you need to follow.
503
+
You can always help by submitting patches or triaging issues, even offering reproduction steps to issues is incredibly helpful!
504
+
505
+
### Running tests
506
+
`rake test` or `bundle exec appraisal rake test` runs everything.
507
+
or run a specific suite using `bundle exec appraisal <appraisal name> rake test`
494
508
- Integration tests run in Headless Chrome which is included in Chrome (59+ linux,OSX | 60+ Windows)
495
509
- ChromeDriver is included with `chromedriver-helper` gem so no need to manually install that 👍
496
-
- Update React assets with `rake react:update`
510
+
511
+
### Updating the pre-bundled react
512
+
- Update React with `rake react:update`
513
+
It outputs an ironically webpacked couple of files into `lib/assets/react-source/<environment>/react(-server).js` where it will be picked up by `sprockets` in `lib/react/rails/asset_variant.rb`
514
+
515
+
### Updating ReactRailsUJS
497
516
- Update the UJS with `rake ujs:update`
498
-
- Releases:
499
-
- To release a new RubyGems version:
500
-
- Increment the version in `lib/react/rails/version.rb`
501
-
- Add an entry to `VERSIONS.md`
502
-
- Update the changelog (find recent changes on GitHub by listing commits or showing closed PRs)
503
-
- Commit changes & push to master
504
-
- `bundle exec rake release`: pushes a tag to GitHub, builds a `.gem`, and pushes to RubyGems
0 commit comments