I’d like to hear from the community on why you would still use React on Rails, and thus Rails, for a new web app, given the many alternatives these days for web apps.
As an experienced Rails developer, React on Rails gives me the best of both worlds. Rails gives me an amazing set of solutions for common problems in web development with sensible defaults. React gives me a fast and clean structure for building UIs. I prefer React on Rails to alternatives because it’s easy to drop into a Rails project and still get all the power of native JavaScript tooling.
I’ve been a Java, PHP, and even .NET developer, web, desktop and mobile. I’ve found in rails a great structured framwork capable of quickly prototyping an app without too much hassle, and moving forward to a more complex application, with great community. I prefered React-on-rails because it seems like right and simple approach to isolate the client code just enough to be able to work as a full front-end developer, full backend developer and fullstack developer within the same project.
So, for a greenfield project, we’ll assume the tech review has been done and the chosen appropriate tech for the project really is rails + react. Giving space for other mixen to exist (asp.net core for instance )
Why react_on_rails? Because when you start pasting together the separate libs: reactjs, then router, oh, then redux, oh then production release minified so webpack, oh then wire together pre-rendering and also websocket support between react and rails … why do you, the architect/tech recommender want to base all that work on your own hand-crafting?
Instead, the react_on_rails gem has had 100’s (1000’s?) of hours of development and production use, and a fully baked test suite.
This of course is the observational reasoning to use as many open source libraries as possible. “On the shoulders of giants” as they say. In this community, every contributor is a giant!
I’ve been playing with Elixir and Phoenix, trying to look for something new to learn and improve my applications. It didn’t take long to realize that I wasn’t utilizing OTP in almost all of my apps and was basically just writing the same code as if I were using Ruby on Rails. Started looking into React and found it to be very fun! However, I wanted a sane solution for server-side rendering, and I was still finding myself coming back to Rails. Found React on Rails not long after and have been playing with it nonstop - it has a very pragmatic approach and it feels like the right direction for Rails and Modern Javascript.
Thanks @hrishio. Full support for JavaScript tooling has been one of our goals from day one!
Thanks, Peter! I’d say that React on Rails is clearly dominating in the Rails space. And my ShakaCode team member @robwise likes to “Run with the herd!” I’d be in trouble if React on Rails wasn’t the herd!
The big question is “Why Rails? given React?”
Thanks @Jose_Ayerdis! @robwise will be happy to hear you like the generators. And we really like the clean separation in the app between the front-end and the back-end parts.
(i will try to not repeat those from above) Why Rails?
(i will be boring here)
stable
fast prototyping
docs/community
convention over configuration
language - just write something in ruby and read it - it’s hard to not understand the code, even for noob like me!
Why with React?
Because it’s not angular
In react more than in other libs community focuses on how to write quality code thats easy to test, easy to understand, and uses guidelines. Many good ideas came from react ecosystem - functional programming in js, components, 1 way flow, flux/redux.
React is small, so it has low learning curve. It’s much easier and faster to learn than other frameworks. But being small is also disadventage - it needs some libs if you want to do some other stuff
JSX - you keep all things in one place, you dont have to jump from js file to html file etc. Another good thing about it is that if you fucked up something in template you will get error message (damn you, angular! burn the witches, burn the witches!)
Stability - react api changes not so often. Facebook stands on newest react BETA so they cannot screw it.
Its damn simple js. No decorators, no magic methods, no other crap. With basic knowledge about js you can do fine in react.
React on Rails has it all. Sticked together already. There is no reason to not love it. It does all the hard work for you.
Any comparisons to alternative frameworks and languages?
Angular. I use it everyday, i cry everyday because of it. The bigger the app is, the more it hurts.
I would use it even though I prefer to use Elm instead of React/Redux for my client framework, because it handles a lot of the fiddly bits of seamlessly integrating a Node(Yarn)/Webpack stack into the Rails asset pipeline and testing stack.
Both via conventions (e.g. file structure, naming, etc) as well as helper code (e.g. auto-recompiling changed client code when running Capybara specs, the Hot vs. Static custom JS/CSS tag helpers, etc.
So, I really use it as “Webpack on Rails”. And it would be nice if the parts of it that weren’t React-specific were separate out, so I could use it without those (even though they don’t hurt, it’s still unnecessary cognitive noise if you aren’t using React).