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

react-rails

 react-rails

Kazuhito Hokamura

December 19, 2014
Tweet

More Decks by Kazuhito Hokamura

Other Decks in Programming

Transcript

  1. app/assets/javascripts/components/post.js.jsx var Post = React.createClass({ getInitialState: function() { return {

    comments: this.props.initialComments }; }, render: function() { var post = this.props.post; var comments = this.state.comments; return ( <div className="post"> <PostHead title={post.title} created_at={post.created_at} commentLength={comments.length} /> <PostBody body={post.body} /> <Comments comments={comments} /> <CommentForm onSubmit={this.handleSubmit} /> </div> ); });
  2. ͜Μͳײ͡ͷ͜ͱΛ΍ͬͯΔʢΠϝʔδʣ def react_component(component, props) jscode = <<-JS #{@react_js} #{@your_components_js} return

    React.renderToString( React.createElement('Post'), #{props.to_json} ); JS ExecJS.exec(jscode).html_safe end
  3. 5JNFQFSSFRVFTU &3# NT )BNM NT 4MJN NT 3FBDU /PEFKT NT

    3FBDU UIFSVCZSBDFS NT BCOIUUQQPTUT