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.7k
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
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
0
150
JIS keyboard support in Omarchy
lef237
0
160
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
dotNET_vulnclicker_intro.pdf
deka_morita
0
150
残高管理から台帳サービスへの進化
artoy
1
210
AmebaブログはKMPから卒業します
kmars0605
0
220
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
150
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
120
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
200
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
950
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.6k
Featured
See All Featured
Visualization
eitanlees
153
17k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
890
Code Reviewing Like a Champion
maltzj
529
40k
Thoughts on Productivity
jonyablonski
76
5.4k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Become a Pro
speakerdeck
PRO
31
6.3k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
860
Accessibility Awareness
sabderemane
1
260
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.