Skip to content

Commit 5a69693

Browse files
committed
Cleanup sections of readme.
WIP Doc
1 parent 273d815 commit 5a69693

File tree

1 file changed

+77
-57
lines changed

1 file changed

+77
-57
lines changed

README.md

Lines changed: 77 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,39 @@
11
# react-rails
22

33
[![Gem](https://img.shields.io/gem/v/react-rails.svg?style=flat-square)](http://rubygems.org/gems/react-rails)
4+
[![npm](https://img.shields.io/npm/v/react_ujs.svg)](https://www.npmjs.com/package/react_ujs)
45
[![Build Status](https://img.shields.io/travis/reactjs/react-rails/master.svg?style=flat-square)](https://travis-ci.org/reactjs/react-rails)
56
[![Gemnasium](https://img.shields.io/gemnasium/reactjs/react-rails.svg?style=flat-square)](https://gemnasium.com/reactjs/react-rails)
67
[![Code Climate](https://img.shields.io/codeclimate/github/reactjs/react-rails.svg?style=flat-square)](https://codeclimate.com/github/reactjs/react-rails)
7-
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/reactjs/react-rails.svg?style=flat-square)](https://codeclimate.com/github/reactjs/react-rails/coverage)
88

9-
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.
1010

11-
If you need to make changes for the prebundled react, see the migration docs here:
12-
https://reactjs.org/blog/2016/11/16/react-v15.4.0.html
13-
https://reactjs.org/blog/2017/04/07/react-v15.5.0.html
14-
https://reactjs.org/blog/2017/06/13/react-v15.6.0.html
15-
16-
`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!
1712

13+
## Learn more
1814
- 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)
2219
- [Generating components](#component-generator) in various formats
23-
- [`ReactRailsUJS`](#ujs) for mounting and unmounting components
2420
- Automatically [camelizing props](#camelize-props)
21+
- [Server-side rendering](#server-side-rendering)
22+
- [`ReactRailsUJS`](#ujs) for mounting and unmounting components
23+
- [Upgrading](#upgrading) 2.3 to 2.4
2524
- [Related Projects](#related-projects)
26-
- [Developing](#development) the gem
25+
- [Contribute to](#contributing) the gem
2726

28-
## Installation
27+
## Get started with Webpacker
2928

30-
Install from Rubygems as `react-rails`.
29+
[or Get started with Sprockets](#use-with-asset-pipeline)
3130

32-
```ruby
33-
gem "react-rails"
34-
```
31+
[Webpacker](https://github.com/rails/webpacker) integrates modern JS tooling with Rails.
3532

36-
Get started with `rails g react:install`:
37-
38-
```
39-
$ rails g react:install
40-
```
41-
42-
## Use with Webpacker
43-
44-
[Webpacker](https://github.com/rails/webpacker) integrates modern JS tooling with Rails. `ReactRailsUJS` allows you to gradually migrate to Webpacker.
45-
46-
Get started by adding `webpacker` to your gemfile and installing `webpacker` and `react-rails`:
33+
Add `webpacker` and `react-rails` to your gemfile and run the installers:
4734

4835
```
36+
$ bundle install
4937
$ rails webpacker:install
5038
$ rails webpacker:install:react
5139
$ rails generate react:install
@@ -57,7 +45,15 @@ This gives you:
5745
- [`ReactRailsUJS`](#ujs) setup in `app/javascript/packs/application.js`
5846
- `app/javascript/packs/server_rendering.js` for [server-side rendering](#server-side-rendering)
5947

60-
When you add a component to `app/javascript/components/`, you can [render it in a Rails view](#view-helper):
48+
Generate your first component:
49+
50+
```
51+
$ rails g react:component HelloWorld greeting:string
52+
```
53+
54+
Your component is added to `app/javascript/components/` by default.
55+
56+
[Render it in a Rails view](#view-helper):
6157

6258
```erb
6359
<%= react_component("HelloWorld", { greeting: "Hello" }) %>
@@ -74,8 +70,6 @@ The component name tells `react-rails` where to load the component. For example:
7470

7571
This way, you can access top-level, default, or named exports.
7672

77-
If `require` fails, `react-rails` falls back to the global namespace approach described in [Use with Asset Pipeline](#use-with-asset-pipeline).
78-
7973
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`:
8074

8175
```js
@@ -85,7 +79,12 @@ var ReactRailsUJS = require("react_ujs")
8579
ReactRailsUJS.useContext(myCustomContext)
8680
```
8781

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.
8988

9089
Component File Name | `react_component` call
9190
-----|-----
@@ -97,7 +96,7 @@ Component File Name | `react_component` call
9796

9897
## Use with Asset Pipeline
9998

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:
101100

102101
```
103102
$ rails g react:install
@@ -113,7 +112,7 @@ This will:
113112

114113
Now, you can create React components in `.jsx` files:
115114

116-
```js
115+
```JSX
117116
// app/assets/javascripts/components/post.jsx
118117

119118
window.Post = createReactClass({
@@ -171,7 +170,7 @@ MyApp::Application.configure do
171170
end
172171
```
173172

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`
175174

176175

177176
## View Helper
@@ -402,7 +401,7 @@ rails g react:component Post title:string published:bool published_by:instanceOf
402401

403402
would generate:
404403

405-
```js
404+
```JSX
406405
var Post = createReactClass({
407406
propTypes: {
408407
title: PropTypes.string,
@@ -480,29 +479,50 @@ You can also specify this option in `react_component`:
480479
<%= react_component('HelloMessage', {name: 'John'}, {camelize_props: true}) %>
481480
```
482481
483-
## Related Projects
482+
## Upgrading
484483
485-
- [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
490485
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.
492487
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:
489+
490+
- https://reactjs.org/blog/2016/11/16/react-v15.4.0.html
491+
- https://reactjs.org/blog/2017/04/07/react-v15.5.0.html
492+
- https://reactjs.org/blog/2017/06/13/react-v15.6.0.html
493+
494+
495+
For the vast majority this will get you most of the migration:
496+
- global find+replace `React.Prop` -> `Prop`
497+
- add `import PropTypes from 'prop-types'` (Webpacker only)
498+
- re-run `bundle exec rails webpacker:install:react` to update npm packages (Webpacker only)
499+
500+
## Contributing
501+
502+
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`
494508
- Integration tests run in Headless Chrome which is included in Chrome (59+ linux,OSX | 60+ Windows)
495509
- 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
497516
- 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
505-
- To release a new NPM version:
506-
- Update the version in `react_ujs/package.json`
507-
- Commit & push to master
508-
- `bundle exec rake ujs:publish` (runs `npm publish`)
517+
- To release a new NPM version:
518+
- Update the version in `react_ujs/package.json`
519+
- Commit & push to master
520+
- `bundle exec rake ujs:publish` (runs `npm publish`)
521+
522+
### Releasing the Gem
523+
- To release a new RubyGems version:
524+
- Increment the version in `lib/react/rails/version.rb`
525+
- Add an entry to `VERSIONS.md`
526+
- Update the changelog (find recent changes on GitHub by listing commits or showing closed PRs)
527+
- Commit changes & push to master
528+
- `bundle exec rake release`: pushes a tag to GitHub, builds a `.gem`, and pushes to RubyGems

0 commit comments

Comments
 (0)