Hi all,
I’m working on a Ruby on Rails app and I’m getting trouble when I try to create a React component that opens within a RoR view.
Here is my view so far:
<%= link_to react_partner_search_advanced_admin_partners_path(project_id: project.id), data: { remote: true, "partner-search-modal": true } do %> <i class="fab fa-searchengin"></i> <% end %>
My action in my controller:
def react_partner_search @project = Project.find(params[:project_id]) render layout: false end
My react_component view:
<%= react_component("PartnerSearchApp", props: { project_address: @project&.project_or_client_full_address }, prerender: false) %>
And my React component:
import React from 'react'; import Modal from 'react-modal'; import { defaultModalStyles } from '../features/utilities/modalStyles'; const PartnerSearchApp = (props) => { return ( <Modal isOpen={true} style={defaultModalStyles} appElement={document.body}> <h1>{props.project_address}</h1> </Modal> ) } export default PartnerSearchApp;
When I click on my link, I’m listening for an "ajax:success"
event. When it is triggered, I retrieve the response from the server. It is an HTML response that contains the whole 3 points exposed on this page: https://www.shakacode.com/react-on-rails/docs/guides/client-vs-server-rendering/
And this is precisely here that I’m stuck: my component is empty and there is no modal or content within it: <div id="PartnerSearchApp-react-component-xxxxx">
How can I retrieve my whole component and add it to my RoR view?
Thank you so much for your help!