There are at least 4 different ways that I'm familiar with and
tons of resources to help you execute the way that works best for you.
Here's the ones I've learned from researching:
1. Approach 1 - CDN based inclusion in header
-
You can include it just as a link on the html pages you want to include
some React functionality. This is as simple as putting it in the header
of the pages.
2. Approach 2 - React Front-end/Rails API backend (pre-existing app)
- Convert controllers into API folders with namespacing technique and create the front-end `client` as shown in Approach 3.
3. Approach 3 - React Front-end/Rails API backend
- This approach works by creating a rails api
- Within the directory of the app run
- Install foreman gem, create Procfile with the following:
RAILS: bundle exec rails s -p 3001
REACT: cd client && npm start
(caveat: If deployed on Heroku, you may need to change `REACT` to `web`.)
- Run servers by
- You will need something like axios in node to make the front-end `client` talk to the rails backend but this works.
4. Approach 4 -React-rails gem install
- This approach, I cannot speak to because it seemed the most .... coupled. In the back of my mind, I tend to think this couples react to rails in a way I, at this level of my knowledge, would not be able to decouple if I were to revert to something else or use Vue or stick to normal html requests.
Forgive me giving my opinion on that last one, if someone has more insight on the gem approach, I'd be happy to hear it.