Module: ReactWebpackRails::ViewHelpers

Included in:
ReactComponentRenderer
Defined in:
lib/react_webpack_rails/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#react_component(name, raw_props = {}, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/react_webpack_rails/view_helpers.rb', line 16

def react_component(name, raw_props = {}, options = {})
  props = raw_props.as_json
  props = Services::CamelizeKeys.call(props) if Rails.application.config.react.camelize_props
  if server_side(options.delete(:server_side))
    result = NodeIntegrationRunner.new('react-component', props: props, name: name).run
    react_element('react-component', { props: props, name: name }, options) do
      result.html_safe
    end
  else
    react_element('react-component', { props: props, name: name }, options)
  end
end

#react_element(integration_name, payload = {}, html_options = {}, &block) ⇒ Object



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

def react_element(integration_name, payload = {}, html_options = {}, &block)
  data = {
    integration_name: integration_name,
    payload: payload,
    react_element: true
  }
  html_options = html_options.merge(data: data)
  html_tag = html_options.delete(:tag) || :div
  (html_tag, '', html_options, &block)
end

#react_router(name) ⇒ Object



29
30
31
32
# File 'lib/react_webpack_rails/view_helpers.rb', line 29

def react_router(name)
  deprecation_warning
  react_element('react-router', name: name)
end