4

I'm trying Rails 6 and found it supports react and webpack very well so i can just render / serve react components from rails controller code: https://github.com/reactjs/react-rails#controller-actions

class TodoController < ApplicationController
  def index
    @todos = Todo.all
    render component: 'TodoList', props: { todos: @todos }
  end
end

That means I will have have web page routing defined on the server via rails routes and controllers (and at same time may still have these controller actions return json as REST api)

How's that compared to have the rails only serve a static page, and use react-router to switch between different react components?

It seems to me client-routing would have better performance as it will share the same redux store, and will not trigger a full page refresh?

smilence
  • 349
  • 4
  • 9
  • I have a similar query. If I use ExpressJS to route the user, i.e. whenever the user wants to go from one page to another, the server sends a new html file with some of content dynamically filled. But part of this new page (inside a div#app) is a React App. React.js and ReactDOM.js are imported in script tags and the custom React-JSX code is also imported in a script tag. Every time the user visits a new page, the server sends a new html file and react app. Would it be right to say that this application is Server-Side-Routed and has a mixture of Client-Side-Rendering and Server-Side-Rendering? – Rohan Hussain Jul 15 '22 at 19:06

0 Answers0