5

I'm using the react-rails gem to integrate react with rails, and I'm conflicted on how I should organize my code.

Is it preferable that I have my core html in the html.erb files or in the jsx files? Currently, I basically made everything a component. All I do in my html.erb files is using the react_component helper to call those components. For example, I would have a ProfileShow.js.jsx file for my profile page and a EditPost.js.jsx for my edit post page.

What is your suggestion?

Novice
  • 575
  • 2
  • 7
  • 16
  • Have a look at this link https://www.airpair.com/reactjs/posts/reactjs-a-guide-for-rails-developers the introduction could help you :) – Pavan Oct 05 '15 at 09:37

2 Answers2

1

I prefer move my react-component's code to js-files. And link them using react_component helper method. It isn't good practice to write your js-code in views.

Sergei Stralenia
  • 855
  • 7
  • 16
0

There are multiple ways to do this. One of the best solutions I seen so far is to write your react jsx components in an app/assets/javascripts/components folder.

Setup a react gem like https://github.com/shakacode/react_on_rails that would help with passing on data as props to the view layer as these would be accessible outside react.

I hope this helps.

Cheers.

Benard O.
  • 1
  • 2