react-rails icon indicating copy to clipboard operation
react-rails copied to clipboard

Namespace help require("items/index") require("items").Index

Open anle1337 opened this issue 7 years ago • 3 comments

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

anle1337 avatar Sep 28 '17 16:09 anle1337

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 avatar Sep 29 '17 17:09 rmosolgo

@rmosolgo I tried that, doesn't seem to work. Did you get it to work?

anle1337 avatar Oct 13 '17 07:10 anle1337

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

rmosolgo avatar Oct 13 '17 15:10 rmosolgo

We have no updates on this. Closing the issue.

alkesh26 avatar Nov 01 '22 08:11 alkesh26