Module: ReactHelper

Includes:
ActionView::Helpers::JavaScriptHelper
Defined in:
lib/react_rails_webpack/app/helpers/react_helper.rb

Instance Method Summary collapse

Instance Method Details

#react_component(component_name, props = {}) ⇒ Object

Props should be a Ruby hash



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/react_rails_webpack/app/helpers/react_helper.rb', line 7

def react_component(component_name, props = {})
  # Give second argument to content_tag some text
  # if you want to test to see if React is properly
  # replacing its content with a component
  (
    :div,
    javascript_tag('renderLastComponentDiv()'),
    class: 'react-component-target',
    data: {
      componentName: component_name,
      componentProps: props.to_json
    }
  )
end