Module: React::Rails::ViewHelper
- Defined in:
- lib/react/rails/view_helper.rb
Instance Method Summary collapse
-
#react_component(name, args = {}, 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, args = {}, 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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/react/rails/view_helper.rb', line 9 def react_component(name, args = {}, = {}, &block) = {:tag => } if .is_a?(Symbol) block = Proc.new{concat React::Renderer.render(name, args)} if [:prerender] = .reverse_merge(:data => {}) [:data].tap do |data| data[:react_class] = name data[:react_props] = React::Renderer.react_props(args) unless args.empty? 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 |