Sha256: 3ac55172aac15c3f9dea34ed1875e3b36055f8497c22c71f85343d63705b6860

Contents?: true

Size: 643 Bytes

Versions: 1

Compression:

Stored size: 643 Bytes

Contents

module ReactForRails
  module Helper
    def react_component(name, options = {})
      props = options[:props] || {}
      props_json = ERB::Util.json_escape(props.is_a?(String) ? props : props.to_json)
  
      id = "react-component-#{SecureRandom.hex(8)}"
  
      html_options = options[:html_options] || {}
      html_options[:id] = id
  
      content_tag(:div, "", html_options) +
        content_tag(
          :script,
          props_json.html_safe,
          type: "application/json",
          "data-dom-id" => id,
          "data-component-name" => name,
          class: "custom-react-component-render"
        )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
react_for_rails-0.0.1 lib/react_for_rails/helper.rb