Do you need React JS for your Ruby on Rails project? For the last few years, the answer has often been a resounding “yes”.
These libraries enable the development of snappy user experiences that previously would have only been possible with React.
Whether you’re building a new Rails frontend or mulling over how to improve an existing Rails monolith, it’s definitely worth considering Hotwire and Turbo as alternative solutions to React.
Here are a few things to keep in mind:
Who are your current and future developers?
When comparing a Rails/Hotwire vs. React solution, it’s important to understand your talent pool.
If your current developers have extensive experience with React, but little with Rails and Hotwire/Turbo, then you may be better off going with a React solution.
On the other hand, if you’re already working with expert Ruby on Rails engineers, it would probably be best to lean toward Rails/Hotwire over React.
It would also be wise to consider your future overhead. If you opt to use React, it’s likely that you’ll need to hire both React and Ruby on Rails developers in the future.
How do you feel about added complexity?
Generally speaking, adding React to an existing Rails application will increase the cost and complexity of your project.
For instance, if you decide to use a Rails backend API and a React frontend, you’ve split your work into two applications using two separate programming languages.
Contrast this against using Rails, Hotwire, and Turbo in a monolithic application. In that case, you’re using a single language to build a single application.
There are pros and cons to both approaches, though the Hotwire option can be beneficial for smaller teams with more constrained budgets.
Yet sometimes the added complexity of React is simply unavoidable because the core features of your product cannot be met by Rails alone.
Here are a few examples:
1. You need a mobile application
If your product or service requires development of a mobile app, you would actually be well-served by dividing your code into a React frontend and Rails backend.
In this scenario, your frontend and mobile application can consume the same Rails backend data.
Even more importantly, much of your frontend React code can be repurposed to build a React Native mobile app, reducing overall cost and development time.
2. You need libraries that work better with React
If your project would be accelerated by leveraging the extensive React ecosystem, then it may be advantageous to favor React vs. Hotwire.
3. You need a high degree of interactivity
And if there are some areas where additional interactivity is needed (e.g. updating a form based on user inputs), the miniscule Stimulus library that is part of the Hotwire ecosystem can often bridge that gap without the need to add React in Rails.
How do you want to build your product?
Ruby on Rails and React have polar opposite philosophies.
The chief advantage of React is that it is simple to use, allowing devs to get started on work quickly.
The disadvantages are that React code can rapidly grow disorganized, large amounts of boilerplate code are often required, and best practices are not always followed.
On the other end of the spectrum, Rails is a large, batteries-included, highly-opinionated framework.
The downside to Rails is that developers are strongly encouraged to do things “the Rails way” and may run into issues when venturing off the beaten path.
The advantage of Rails is that best practices are enforced by default, and code tends to follow idiomatic patterns that every Rails developer will be familiar with.
These properties make Ruby on Rails ideal for the rapid development of robust, secure, well-written, and well-tested applications.
So are Rails and Hotwire better than React for your project?
In a 2022 presentation, well-known rubyist Yaroslav Shmarov discusses the surprising degree of interactivity you can achieve with Hotwire, Turbo, and Stimulus.
But in that same presentation he also states, “I don’t think it’s really right to [say] Hotwire is better or React is better…these are different tools for different jobs.”
New tools like Hotwire, Turbo, and Stimulus haven’t eliminated the need for React in all applications – they’ve simply reduced the number of applications that require React.
So whatever you’re working on, it’s probably worth considering the pros and cons of keeping React in your tech stack.
If you are tasked with deciding whether React or Hotwire is the best fit for your application, please contact The Gnar Company. We can schedule time to discuss your application(s) and recommend the best technology option for your organization. All initial consultations are free.