Upgrade to Pro — share decks privately, control downloads, hide ads and more …

react-rails

 react-rails

Kazuhito Hokamura

April 24, 2015
Tweet

More Decks by Kazuhito Hokamura

Other Decks in Programming

Transcript

  1. Key Features • JSX compilation in the Rails asset pipeline

    • React component mounting with a view helper & UJS • Server-side rendering
  2. // ※ ίʔυ͸Πϝʔδ findAll('[data-react-class]').forEach((el) => { var reactClass = el.dataset.reactClass;

    var reactProps = el.dataset.reactProps; var component = window[reactClass]; var props = JSON.parse(reactProps); var reactElement = React.createElement(component, props); React.render(reactElement, el); }); react_ujs
  3. <%= react_component('MyComponent', { name: 'hokaccha' }, { prerender: true })

    %> # => <div data-react-class="MyComponent" data-react-props='{"name":"hokaccha"}'> <div data-react-checksum="xxx">Name: hokaccha</div> </div>