DEV Community

Discussion on: Why and When should you use React with Ruby on Rails

Collapse
 
adamklepacz profile image
Adam Klepacz • Edited

One thing to mention is that you shouldn't put React within Rails views.
Ruby on Rails is a fully MVC(model view controller) architecture app where views are also created by this framework. It follows the traditional pattern of building a web app, with static routing, where whenever a user click, a page is reloaded etc.( except of turoblinks feature). Putting React components within .erb files, where React was created to work as an independent app, with dynamic routing, state management library is a huge antipattern to follow.

To clarify, React can work well with Ruby On Rails only if Ruby is working as a separated back-end service aka rest API, transferring data from the database to the client app made with React, and React exists as an independent separated app with state management library and communicates with rails via API.

Collapse
 
karan_shah89 profile image
Karan Shah

No, not necessarily true. What you're saying is the way many people use it but you can definitely use it within the views.

Since 5.2.x, support for Angular, Vue and React is baked inside the framework. There's even an option to use React when you're creating the project or just simply use the react-rails gem!

Websites like Fiverr and even Airbnb use in this manner

Collapse
 
dandush03 profile image
Daniel Laloush

I think it's more about if we want to scale our Website to mobile, then using rails as api will be indispensable

Collapse
 
karan_shah89 profile image
Karan Shah

True that. Unless you're thinking of PWAs.