Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
react-rails
Search
Kazuhito Hokamura
December 19, 2014
Programming
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
react-rails
Kazuhito Hokamura
December 19, 2014
More Decks by Kazuhito Hokamura
See All by Kazuhito Hokamura
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.3k
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
5.2k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.9k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.7k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
520
RailsエンジニアのためのNext.js入門
hokaccha
7
22k
Cookpad Summer Internship 2021 Web Frontend
hokaccha
0
7.4k
巨大なモノリシック Rails アプリケーションの マイクロサービス化戦略 / 2019 microservices in cookpad
hokaccha
3
4.1k
巨大なRailsアプリケーションを「普通」にするための取り組み
hokaccha
1
1.1k
Other Decks in Programming
See All in Programming
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
340
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
4.8k
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.3k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
120
APNsからLive Activityを開始する話
yumnumm
0
150
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
380
Workers Cache を知る
syumai
0
320
Webの地図
yosuke_furukawa
PRO
6
5k
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
290
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
530
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
340
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
The Limits of Empathy - UXLibs8
cassininazir
1
700
WENDY [Excerpt]
tessaabrams
14
40k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
710
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
550
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
960
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Transcript
react-rails JSΦδαϯ #4
@hokaccha
React • FacebookͷJavaScriptϥΠϒϥϦ • Virtual DOMͱ͍͏ΈΛ͍͍ͬͯײ͡ʹ ViewΛॻ͚Δ • Reactʹ͍ͭͯͷ࣭ @mizchi
ࢯ @koba04 ࢯ ʹ͓ئ͍͠·͢
reactjs/react-rails
Features • react.js͕Asset Pipeline͔ΒrequireՄೳʹͳΔ • JSXͷίϯύΠϧ • scaffoldͰͻͳܗ࡞ • αʔόʔαΠυϨϯμϦϯά༻view
helper
αʔόʔαΠυϨϯμϦϯά
Why? • APIΛͬͯJavaScriptͰϨϯμϦϯά͢Δͱ • ॳظද͕͍ࣔ • JS͕ཧղͰ͖ͳ͍ΫϩʔϥʔͳͲ͔Β ΞΫηεͰ͖ͳ͍
Why? • ॳظඳըαʔόʔʢRubyͳͲʣͰɺ ΓΫϥΠΞϯτͰͬͯΔͱ • ViewͷςϯϓϨʔτϩδοΫ͕ೋॏʹ ͳͬͯ͠·͏
ղܾࡦ • ViewΛڞ௨Խ͢Δ • ಉ͡ίʔυͰαʔόʔ/ΫϥΠΞϯτ྆ํͰ HTMLΛ࡞ΕΕΑ͍ • ReactαʔόʔαΠυͰHTMLΛ࡞ΕΔ
DEMO HJUIVCDPNIPLBDDIBSFBDUSBJMTFYBNQMF
Έ • execjsͱ͍͏ruby͔ΒJSΛ࣮ߦͰ͖ΔgemΛ͏ • αʔόʔଆͰReact. renderToStringΛݺͿ • react_ujs͍ͬͯ͏͕ͭΫϥΠΞϯταΠυͰ ϨϯμϦϯάࡁΈͷComponentΛϚϯτ͢Δ
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> ); });
app/views/posts/show.html.erb <%= react_component('Post', { post: @post, initialComments: @post.comments }, {
prerender: true }) %>
͜Μͳײ͡ͷ͜ͱΛͬͯΔʢΠϝʔδʣ 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
Performance
5JNFQFSSFRVFTU &3# NT )BNM NT 4MJN NT 3FBDU /PEFKT NT
3FBDU UIFSVCZSBDFS NT BCOIUUQQPTUT
Routing
Turbolinksʹϫϯνϟϯ ͋ΔՄೳੑ
Turbolinksͷͱ͖ prerender͠ͳ͍ <%= react_component('Post', { posts: @posts }, { prerender:
!turbolinks_request? }) %>
Thanks.