-
Notifications
You must be signed in to change notification settings - Fork 755
Create render_react_component controller helper #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
bd5a131
to
b71b1c9
Compare
end | ||
end | ||
|
||
ActionController::Base.send(:include, React::Rails::ControllerHelper) if defined?(Rails) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this go in an active support hook?
See for example how react-rails includes the view helper, also here's an ActionController example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done here 2cc9748
👍 Although I don't have a place to use it, I think this is a fitting feature. It would be nice if took a Also, before merging, it should be added to the readme! |
@__react_component_args = args | ||
@__react_component_block = block | ||
|
||
render inline: '<%= react_component(*@__react_component_args, &@__react_component_block) %>', layout: current_layout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just merge in passed options and send to render, so someone can easily override layout/ status or other render options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is pretty useful, as more people are using complete view contents to be served from a React Component, although this deviates from semantics of render and hides render inline: react_component('TodoList'), layout: 'my_layout' |
@vipulnsward that is nice, |
2cc9748
to
3073fe6
Compare
@vipulnsward That's an idea, but I'd rather not have to specify the layout for every action. By default rendering inline will not use a layout. |
4e77a12
to
69625fb
Compare
- CI doesn't seem to like uris that aren't prefixed with a /
Are there other "renderers" out there that we can mimic for API? Personally I also find piggybacking on Rails'
Can't you just specify it once in the controller? |
@zpao I could probably make something like that work. Would rather use a custom renderer than calling render component: "TodoList", data: {...}, options: { prerender: true }, layout: ..., status: ... (
|
render_react_component
allows you to render a React component in place of a typical rails template fromapp/views
.Instead of creating a view that only renders a component, e.g.
You can create call the helper from the controller action instead, e.g.