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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
4.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
510
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
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
150
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
730
アクセシビリティから考える情報設計
high_g_engineer
0
380
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
250
FreeBSDでZabbixを動かす
kenkino
0
300
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
440
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
150
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
130
PL/pgSQLはなぜ「ふつうのSQL」より遅いのか
tameguro
0
110
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
440
What We Talk About When We Talk About XP
m_seki
2
650
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Leo the Paperboy
mayatellez
10
2.3k
Documentation Writing (for coders)
carmenintech
77
5.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
340
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
550
30 Presentation Tips
portentint
PRO
1
400
RailsConf 2023
tenderlove
30
1.5k
Prompt Engineering for Job Search
mfonobong
0
450
Building an army of robots
kneath
307
46k
Building AI with AI
inesmontani
PRO
1
1.2k
A designer walks into a library…
pauljervisheath
211
25k
Paper Plane
katiecoart
PRO
4
53k
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.