~cytrogen/masto-fe

ref: d7254bd3327c5ad208b7f74aade749234441b3bc masto-fe/app/helpers/react_component_helper.rb -rw-r--r-- 540 bytes
d7254bd3 — Laura Hausmann Update default local-settings 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module ReactComponentHelper
  def react_component(name, props = {}, &block)
    data = { component: name.to_s.camelcase, props: Oj.dump(props) }
    if block.nil?
      div_tag_with_data(data)
    else
      content_tag(:div, data: data, &block)
    end
  end

  def react_admin_component(name, props = {})
    data = { 'admin-component': name.to_s.camelcase, props: Oj.dump(props) }
    div_tag_with_data(data)
  end

  private

  def div_tag_with_data(data)
    content_tag(:div, nil, data: data)
  end
end