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 Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
2
140
自作OSでスライド発表する
uyuki234
1
4k
えっ!!コードを読まずに開発を!?
hananouchi
0
270
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
550
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
180
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
620
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.8k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
390
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.1k
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
460
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
AIが無かった頃の素敵な出会いの話
codmoninc
1
270
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
430
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
It's Worth the Effort
3n
188
29k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Unsuck your backbone
ammeep
672
58k
RailsConf 2023
tenderlove
30
1.5k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
GitHub's CSS Performance
jonrohan
1033
470k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
Accessibility Awareness
sabderemane
1
160
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.