Do you use React in combination with Rails in production apps? Does it fit? What is the best way to combine them (gems vs separate backend & frontend apps)?
Cover image by Austin Smart on Unsplash
Do you use React in combination with Rails in production apps? Does it fit? What is the best way to combine them (gems vs separate backend & frontend apps)?
Cover image by Austin Smart on Unsplash
For further actions, you may consider blocking this person and/or reporting abuse
Drishti Jain -
Fady Nabil -
Marino -
Onurhan -
Top comments (2)
We use a library called React On Rails at my job. We love it. We chose this, along with their documented recommended project structure for a couple of reasons.
We wanted to be somewhat flexible for the future, as our app is growing and becoming more used every day. Flexibility was a priority for us in case we ever did want to split up the monolith and have a stand-alone react app for one of the 3 frontends. React On Rails allowed us to build a full react app inside of our monolith, without having to worry too much about asset pipeline or anything. This also allowed us to utilize the full power of Webpack & JS ecosystem.
We also wanted to up our UI game quite a bit, and allowing React to handle the entire UI was definitely part of our goals. The project structure helps with this quite a bit, instead of sprinkling react components in rails views, we would render one component that contains the entire application. Sprinkling is still an option though if you wanted.
Our app is 4-5 years old and had a lot of logic that needed to be "rediscovered," so with this library we were able (with some hacks) to slowly cross over instead of fully rewriting our application at once. We have a combination of rails, backbone, and react all playing somewhat nice together till our rewrite is complete.
Data is handed down via props, which come from the rails view, or via a redux store, which is hydrated in the controller, or via standard RESTful API. Components can be SSR'd as well if you choose, just some additional configuration is needed, especially if you want to use something like styled-components.
We also didn't have to mess too much with the asset pipeline. React on Rails hooks straight into it to run your main production compilation command which works great for us. We didn't have the time or resources to look more closely at using the Webpacker gem, but we didn't need to since we just had normal Webpack running and React on Rails running it.
It should be noted, that understandably so, the company that maintains React on Rails has a premium version which is paid and comes with some enhanced support options from their team. The features of this I'm not 100% sure on but I do know that some advanced caching and better SSR support is part of the package. They seem like a really great team though from our small interactions with them.
This works for us and gives us the nicities of the JS ecosystem for the UI and the stability and predictability of Rails on the backend. Also using documentation generators like Storybook or StyleGuidist is really easy. I love Ruby and JS so it's a pretty ideal stack imo.
This probably won't work for every team, but for our team, and how fast our product moves, this is working great.
Thanks for such a comprehensive response 👍