Rendering a react component in Ruby on Rails partial

Viewed 723

Is it possible to render a react component in a rails partial through an AJAX call? Basically for performance reasons, I have to do some condition checks in order to render and initialize a react component in rails view. I cannot require the react JS upfront as well. I am thinking about rendering a partial through AJAX call and replacing the html in the view from jQuery. I am using react-rails for this purpose.

I'm not sure if this is the best way to do it. Other alternatives would be helpful too.

2 Answers

checked react-rails source code and had to manually call ReactRailsUJS.handleMount() via javascript.

For me, calling ReactRailsUJS.mountComponents() fixed my issue.

Related