Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
5.1k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.8k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.6k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
490
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
Web Frontend Improvement in Cookpad
hokaccha
1
1.2k
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
6k
A2UI という光を覗いてみる
satohjohn
1
140
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
1B+ /day規模のログを管理する技術
broadleaf
0
100
Claspは野良GASの夢をみるか
takter00
0
200
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
170
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
130
Performance Engineering for Everyone
elenatanasoiu
0
200
RTSPクライアントを自作してみた話
simotin13
0
620
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
670
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
170
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
210
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
210
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
Code Review Best Practice
trishagee
74
20k
Automating Front-end Workflow
addyosmani
1370
210k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Faster Mobile Websites
deanohume
310
32k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Building Adaptive Systems
keathley
44
3.1k
Thoughts on Productivity
jonyablonski
76
5.2k
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.