Skip to content

Using Redux with react-rails #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
woniesong92 opened this issue Feb 28, 2016 · 8 comments
Closed

Using Redux with react-rails #486

woniesong92 opened this issue Feb 28, 2016 · 8 comments

Comments

@woniesong92
Copy link

Is it not possible to use Redux with this gem?

I am aware of react_on_rails but I don't want to migrate to another gem which can lead to unnecessary complexities.

@rmosolgo
Copy link
Member

There's no reason you can't use Redux with this gem! You can use this gem to transform JSX and insert React components into Rails views. Your React components can interact with Redux any way they want!

@woniesong92
Copy link
Author

@rmosolgo Thank you so much for your answer. This was rather a non-fruitful question. If you don't mind answering a few more, I am curious about the following:

  1. Do you think react-rails necessarily couples frontend and backend?
  2. What advantage does react-rails provide compared to a node-packaged React?

@rmosolgo
Copy link
Member

Do you think react-rails necessarily couples frontend and backend?

Yes, to the same degree that off-the-shelf Rails couples frontend to backend. I think this is a feature: There's only one project -- no overhead for switching projects (same repository, same development team, same build tools, same deployment strategy). Because they are "coupled", you can fetch exactly the data you need when you need it.

It makes it very easy to add new features and fix things, which is what people really want :shipit:

What advantage does react-rails provide compared to a node-packaged React?

I think the biggest advantage is that you don't have to use Node.js 😆. npm is not great. For "normal" Rails developers (or any developer who started of with <script> tags), the cognitive overhead of require (or import) makes development and in-browser debugging harder. The asset bundlers (webpack, browserify) are good, but they aren't better than Sprockets (maybe rollup is, but nobody uses that, right?).

I'm happy to stay heavy on Rails and light on Node.js. There are a few nice things that I'd like (named imports, sourcemaps), but I don't think they're worth all the overhead they bring with them!

@woniesong92
Copy link
Author

👍 👍 Thanks!!

@woniesong92
Copy link
Author

@rmosolgo I actually tried to setup redux but haven't succeeded yet.
What do you think is the easiest way to setup redux to get it work with react-rails gem?

@rmosolgo
Copy link
Member

Hmm, what I do with dependencies is:

  • Grab a pre-built version (for example cdnjs)
  • Put it in assets/javascripts/vendor/{library-name}-v{version}.js
  • Add to application js //= require vendor/{library-name}-v{version}

Then the library's object is available as a global (eg, window.Redux).

Does that flow work with Redux?

@justin808
Copy link
Collaborator

@woniesong92 You might consider https://github.com/shakacode/react_on_rails/. We have built-in support for Redux, including a Rails generator. See http://www.reactrails.com/ for a live example.

@silouanwright
Copy link

@rmosolgo I'm also running into issues using redux: #878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants