Class: ReactComponent

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-react-component/react_component.rb,
lib/jekyll-react-component/react_component/params.rb

Defined Under Namespace

Classes: Params

Instance Method Summary collapse

Constructor Details

#initialize(tag, params, tokens) ⇒ ReactComponent

Returns a new instance of ReactComponent.



10
11
12
13
# File 'lib/jekyll-react-component/react_component.rb', line 10

def initialize(tag, params, tokens)
  parse_params(params)
  super
end

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jekyll-react-component/react_component.rb', line 15

def render(context)
  @code = super

  <<~CODE
    <div id="#{@id}"></div>
    <script type="module">
      import React from 'react';
      import ReactDOM from 'react-dom';
      import htm from 'htm';
      const html = htm.bind(React.createElement);
      #{@code}

      ReactDOM.render(html`<${#{@name}} #{pass_props} />`, document.getElementById('#{@id}'));
    </script>
  CODE
end