Comments (3)
Hi @xionon, I like the idea of having this kind of generators, specially this one for scaffold.
Maybe we could have something like an unique scaffold generator for both rails and react.
Assuming react is installed, maybe generate the react scaffold files when running the rails generate scaffold
command and generate all the necessary files with just one single command line.
What do you think?
from react-rails.
I have been trying to think that through. Let's say you generate a scaffold for Post.
<!-- app/views/posts/show.html.erb -->
<%= react_component 'Post', { post: @post }, { prerender: true } %>
<!-- app/views/posts/index.html.erb -->
<%= react_component 'PostTable', { posts: @posts }, { prerender: true } %>
and PostTable
would render a list of PostTableRow
objects, keeping with the Rails convention of scaffolding a table for the index view.
Those are pretty easy. The scaffolded edit.html.erb and new.html.erb could be quite similar.
<%= react_component 'PostForm', { post: @post }, { prerender: true } %>
In this example, the form would need to reflect on the post object to determine if it was an edit or new object. Using only Rails' default JSON serializer, I think checking for an id
property would be sufficient.
However, I don't think this quite hits the nail on the head. Sure, you get the react_component
calls stubbed out for you, but it's not really clear why you would want them in separate ERB templates like that. It leaves the whole question of client-side routing and data updates up to the developer.
e.g., when you click the "show" link from the posts index, you'll just get routed to Rails, which will render the component and send you a new page. You've lost the whole advantage of having a front-end JS library. I think that, if the react-rails gem is going to fully take over the default Rails scaffolds, it should also have an opinion on client-side routing.
Maybe I'm wrong on that, though? Maybe it's totally fine to start with server-side rendering, and let the developers worry about catching clicks and rendering a different component.
Philosophically, SHOULD react-rails provide a front-end routing solution? There are a couple out there, rackt/react-router and andreypopp/react-router-component both look like they should work on the server, but I'm not familiar enough with the JavaScript landscape to know if those are appropriate solutions or not. I could also see the argument that it should be done with a different gem - maybe flex-rails
😎
from react-rails.
Good question about the front-end routing. I would like to hear from others about this.
flex-rails
is a very nice name for a gem. ;)
from react-rails.
Related Issues (20)
- Import react_component but it' shown HOT 2
- compare/contrast and migration steps to react_on_rails HOT 5
- Component doesn't render on jsbundling-rails webpacker HOT 5
- Component not loading in rails app HOT 5
- react-rails v3.1.0 is broken HOT 1
- server_rendering.js not found following README HOT 8
- Re-organize documentations in docs folder
- server_rendering.js not found following README HOT 1
- How do I handle styling?
- esbuild HOT 1
- Error related to server_rendering.js not found with SSR HOT 3
- Setup StrictMode for components HOT 2
- get started docs r-r version HOT 1
- Rails 7.1 Renders Partial Header HOT 1
- Server side rendering `window` behaves differently than Node.js? HOT 4
- Issues with Loading React Component for Cuprite in Rails 7.1 HOT 1
- Hooks not working due to Invalid Hook Call HOT 3
- Move react_ujs to es module flow
- Error when use React component other than HelloWorld HOT 1
- Different order for React rendering / DOM ready event in Webkit with React 18 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-rails.