React-rails: Where should I put ReactRailsUJS.mountComponents() to manually mount component?

Created on 4 Jul 2016  路  4Comments  路  Source: reactjs/react-rails

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.
  • [ ] 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.
  • [x] I have another issue to discuss.

(Describe your issue here)

I'm dealing with an issue like #245 . I understand what you guys was talking about but I don't know where to put ReactRailsUJS.mountComponents(). I have some experiences with ReactJS before but not with React Rails. Thank you in advance.

I tried this
screen shot 2016-07-04 at 17 04 39

Most helpful comment

Did you add //= require react_ujs to application.js ? react_ujs creates the ReactRailsUJS object

All 4 comments

ReactRailsUJS is a javascript object, not a Ruby object. So, to call its functions in an ERB file, you should use <script> tags, for example:

<%= react_component ... %>
<script>
  ReactRailsUJS.mountComponents()
</script>

This way, the function will be called in the browser when someone loads the page!

@rmosolgo I got this in browser console. Am I missing something?

screen shot 2016-07-05 at 11 31 59

Did you add //= require react_ujs to application.js ? react_ujs creates the ReactRailsUJS object

I found it. My app used more than one application.js so it's missing. Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings