Integration Methods
There are four different ways to use React on Rails:
- Using only Rails 5 webpack methods
- Using Rails API mode and React separately
- Using react_on_rails gem
- Using react-rails gem
1. Using Only Rails 5 Webpack Methods
## Create a new Rails app with React and PostgreSQL
rails new lyntour --webpack=react --database=postgresql -T --skip-coffee --skip-sprockets
2. Using Rails API Mode and React Separately
## Create a new Rails app in API mode
rails new _5.1.5_ lyntour-api --api --database=postgresql -T
## Create React app separately in a different directory
npx create-react-app lyntour-front
3. Using react_on_rails Gem
## Create a new Rails app with React
rails new lyntour --webpack=react --database=postgresql -T
## Install react_on_rails and dependencies
rails generate react_on_rails:install
bundle && yarn
4. Using react-rails Gem
## Create a new Rails app
rails new lyntour
cd lyntour
## Add required gems to Gemfile
## gem 'webpacker'
## gem 'react-rails'
## Install dependencies
bundle install
rails webpacker:install # OR (on Rails version < 5.0) rake webpacker:install
rails webpacker:install:react # OR (on Rails version < 5.0) rake webpacker:install:react
rails generate react:install
Recommended Approaches
My preferences are methods 1 and 2.