0

I need to convert at least small part of existing RoR + React + Redux app to React on Rails with Server Side rendering for measure performance and effort.

Already made setup from this tutorial shakacode/react_on_rails_demo_ssr_hmr (previous version). And SSR is working for HelloWorld. But how to pull out needed component and make it work with SSR is a tough call. Following this tutorial with my is no help I a different errors all way long. I tried to render component from my app on /hello_world page from tutorial (with all steps with registering component for SSR) but got this:

 Field 'browser' doesn't contain a valid alias configuration
    using description file: /app/package.json (relative path: ./app/frontend/folder/my_component_server.js)
      no extension
        Field 'browser' doesn't contain a valid alias configuration

Also markup could be confusing because React on Rails needs declared component in .erb template, while I already included React app as following in my haml file:

 %div#root <-- here is attaching react app
   = stylesheet_pack_tag "fonts", "styles"
   = javascript_pack_tag "my_react_app_entry_point"
user2791999
  • 178
  • 2
  • 14

1 Answers1

0

Just use this gem (https://github.com/reactjs/react-rails)

Everything you need to get starting is in readme. This gem allows you to create React components and use in rails view by simply execute:

<%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
sectasy
  • 98
  • 2
  • 8
  • But react-on-rails provide same and even more functionality it was chosen mainly for greater SSR. But simple examples didn't show direction what to do with complex already in prod applications. – user2791999 Jun 23 '22 at 14:39