Hacker News new | past | comments | ask | show | jobs | submit login

Is there a convincing Stimulus vs. React-Rails post anywhere?



They are both JS frameworks, but they are fundamentally different approaches.

React (and React-rails) moves rendering / state / logic clientside. You can use tools like react-rails to more easily pass data from your Rails controller to your react components (basically conveniences to create props from instance variables).

Stimulus doesn't handle rendering at all. It's intended to be used for small little "sprinkles" of JavaScript (think things like: showing / hiding content, toggling classes, basic event handlers). If you used to write jQuery snippets to wire up a click event to run ~5-10 lines of JS, then you might look at Stimulus as a more modern implementation (es6, mutationobserver, etc). Stimulus plays nicely with Turbolinks since it needs existing HTML (servered rendered from normal Rails views) to attach to.

You're basically looking at two diverging paths: do you go down a JS-driven SPA application with React (or some kind of hybrid where you have React do parts of the page) or do you opt for Basecamp's "I cant belive its not a SPA" approach with Turbolinks, server-rendered HTML, and Stimulus for small interactivity.

Here's a talk I gave at the London Ruby meetup about Stimulus and in what contexts you might want to use (or not use it): https://assets.lrug.org/videos/2020/september/matt-swanson-s...


What you are describing seems similar to good old BackboneJS?


Or a convincing Stimulus vs. Vue post would be helpful too, since Vue is so simple to sprinkle in as well, and doesn't pollute the html with data attributes as much as Stimulus.


One benefit is when combined with Turbolinks there is a need to bootstrap the Vue/React component. The Stimulus controllers respond to mutation observers and always work.

If a new HTML element is added to the DOM and has a controller, it just works and is now active. This might not be the case with React or Vue, as you'd have to then bootstrap the component.

This makes Stimulus a really good combo when used with Turbolinks or partial Javascript responses.


I switched from Stimulus to Vue and have had a much better experience so far. It is much easier for me to use and I still get the value of "sprinking"


Not sure about react-rails but using Stimulus as part of StimulusRelex[1] is super interesting to me.

1. https://docs.stimulusreflex.com/


Stimulus is paired with Turbolinks, which doesn't play well with almost anything in the JS ecosystem.


This used to be accurate in the days of auto initializing jquery plugins, but probably isn’t the case today if you’re actually using stimulus.


It still is problematic if you use third party plugins / saas vendors.

Not all. But many. Things like zendesk integrations for example. YMMV


Stimulus has nothing to do with Turbolinks.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: