class React::Rails::ControllerRenderer
A renderer class suitable for ‘ActionController::Renderers`. It is associated to `:component` in the Railtie
.
It is prerendered by default with {React::ServerRendering}. Set options to ‘false` to disable prerendering.
@example Rendering a component from a controller
class TodosController < ApplicationController def index @todos = Todo.all render component: 'TodoList', props: { todos: @todos }, tag: 'span', class: 'todo' end end
Attributes
output_buffer[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/react/rails/controller_renderer.rb, line 23 def initialize(options={}) controller = options[:controller] @__react_component_helper = controller.__react_component_helper end
Public Instance Methods
call(component_name, options, &block)
click to toggle source
@return [String] HTML for ‘component_name` with `options`
# File lib/react/rails/controller_renderer.rb, line 29 def call(component_name, options, &block) props = options.fetch(:props, {}) options = default_options.merge(options.slice(:data, :aria, :tag, :class, :id, :prerender, :camelize_props)) react_component(component_name, props, options, &block) end
Private Instance Methods
default_options()
click to toggle source
# File lib/react/rails/controller_renderer.rb, line 37 def default_options { prerender: true } end