0

Sorry for the slightly generic question. I am working on a Ruby on Rails and React.js based app using the react_rails gem and have reached a point where I need the ability to require modules across JS files.

I have tried every example I can find but seem to constantly have problems integrating things in a way that will allow module.exports = 'XXXXX'.

I was wondering if anyone can point me in the direction of a solid working example or can explain the best way to allow this using the react_rails gem?

y.bregey
  • 1,469
  • 1
  • 12
  • 21
Tom Pinchen
  • 2,467
  • 7
  • 33
  • 53

1 Answers1

0

When we install react_rails gem, the file 'components.js' will be added to '/app/assets/javascript' with content:

//= require_tree ./components

That means every single javascript file in '/app/assets/javascript/components' folder will be loaded.

So when we define a new react class, just put the source file to '/components',

When you define a new react class, just put it in '/components/'. So don't worry about something like "module.exports = 'XXXXX'" anymore, Rails does it for us already. Otherwise, you may need to modify 'components.js'

Hieu Pham
  • 6,577
  • 2
  • 30
  • 50