Module: ReactWebpackRails::ViewHelpers

Defined in:
lib/react_webpack_rails/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#react_component(name, props = {}, options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/react_webpack_rails/view_helpers.rb', line 4

def react_component(name, props = {}, options = {}, &block)
  options = { tag: options } if options.is_a?(Symbol)

  html_options = options.reverse_merge(data: {})
  html_options[:data].tap do |data|
    data[:react_class] = name
    data[:react_props] = (props.is_a?(String) ? props : props.to_json)
  end
  html_tag = html_options[:tag] || :div
  html_options.except!(:tag)

  (html_tag, '', html_options, &block)
end