Module: React::Rails::ViewHelper
- Defined in:
- lib/react/rails/view_helper.rb
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.
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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/react/rails/view_helper.rb', line 7 def react_component(name, props = {}, = {}, &block) = {:tag => } if .is_a?(Symbol) = [:prerender] if block = Proc.new{ concat React::ServerRendering.render(name, props, ) } end = .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, :prerender) content_tag(html_tag, '', , &block) end |