react-rails
react-rails copied to clipboard
Namespace help require("items/index") require("items").Index
Help us help you! Please choose one:
- [ ] My app crashes with
react-rails
, so I've included the stack trace and the exact steps which make it crash. - [X] My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
- [ ] I'm trying to use
react-rails
with another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working. - [ ] I have another issue to discuss.
So I understand how to use the view helper to get this: react_component("items/index") require("items/index")
--app --javascript --components --items --Index.js
But how do I pass "items.Index" as an argumnet like this: react_component("items.Index") require("items").Index
--app --javascript --components --items --Index.js ??? idk
Hi, good question! You could write JS like this:
// app/javascript/components/items.js
class ItemsIndex extends React.Component {
// ...
}
module.exports = {
Index: ItemsIndex,
// ... Maybe other components are exported here
}
So, the exported value is an object with the key Index
. Does that work for you?
@rmosolgo I tried that, doesn't seem to work. Did you get it to work?
Here's the test case:
- ERB view: https://github.com/reactjs/react-rails/blob/master/test/dummy_webpacker3/app/views/pack_components/show.html.erb#L5
- JavaScript: https://github.com/reactjs/react-rails/blob/master/test/dummy_webpacker3/app/javascript/components/named_export_component.js#L4
We have no updates on this. Closing the issue.