Class: React::Rails::ComponentMount
- Inherits:
-
Object
- Object
- React::Rails::ComponentMount
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/react/rails/component_mount.rb
Overview
This is the default view helper implementation. It just inserts HTML into the DOM (see #react_component).
You can extend this class or provide your own implementation by assigning it to ‘config.react.view_helper_implementation`.
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
Instance Method Summary collapse
-
#react_component(name, props = {}, options = {}, &block) ⇒ Object
Render a UJS-type HTML tag annotated with data attributes, which are used by react_ujs to actually instantiate the React component on the client.
-
#setup(env) ⇒ Object
ControllerLifecycle calls these hooks You can use them in custom helper implementations.
- #teardown(env) ⇒ Object
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
11 12 13 |
# File 'lib/react/rails/component_mount.rb', line 11 def output_buffer @output_buffer end |
Instance Method Details
#react_component(name, props = {}, options = {}, &block) ⇒ Object
Render a UJS-type HTML tag annotated with data attributes, which are used by react_ujs to actually instantiate the React component on the client.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/react/rails/component_mount.rb', line 25 def react_component(name, props = {}, = {}, &block) = {:tag => } if .is_a?(Symbol) props = camelize_props_key(props) if camelize_props_switch = .reverse_merge(:data => {}) [:data].tap do |data| data[:react_class] = name data[:react_props] = (props.is_a?(String) ? props : props.to_json) end html_tag = [:tag] || :div # remove internally used properties so they aren't rendered to DOM .except!(:tag) content_tag(html_tag, '', , &block) end |
#setup(env) ⇒ Object
ControllerLifecycle calls these hooks You can use them in custom helper implementations
16 17 |
# File 'lib/react/rails/component_mount.rb', line 16 def setup(env) end |
#teardown(env) ⇒ Object
19 20 |
# File 'lib/react/rails/component_mount.rb', line 19 def teardown(env) end |