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がなぜ素晴らしいのか
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yuichiro MASUI
March 18, 2015
Programming
20k
44
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactがなぜ素晴らしいのか
詳しくはこちらへ →
https://www.facebook.com/groups/toretatech/
Yuichiro MASUI
March 18, 2015
More Decks by Yuichiro MASUI
See All by Yuichiro MASUI
Coding Agent用チケットシステム - ticket.sh
masuidrive
0
59
Vue/Nuxt tutorial for Sendai
masuidrive
0
220
ハッカソンで 作ったアプリを売却した話
masuidrive
0
710
DJ hands on for IT Engineers
masuidrive
1
220
自分の棚卸をして レジュメを書こう
masuidrive
5
2k
0から1ヶ月で DJになるまで
masuidrive
4
1.6k
Google Apps Scriptでbotを作る話
masuidrive
1
1.8k
Rails loves React
masuidrive
1
550
トレタの存在理由
masuidrive
0
260
Other Decks in Programming
See All in Programming
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
190
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
150
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
210
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
840
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.3k
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
420
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
240
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.2k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
360
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
430
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
350
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
970
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
My Coaching Mixtape
mlcsv
0
170
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
30 Presentation Tips
portentint
PRO
1
340
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
340
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
460
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Transcript
React.js͕ ͳͥૉΒ͍͠ͷ͔ Yuichiro MASUI <
[email protected]
> Toreta, Inc CTO
DOMૢ࡞ͳ͍ͥ͠ͷ͔ <div id=“item-1”> <span id=“item-1-text” class=“hidden”>foo</span> </div> ͜ͷλάݟ͑ͯΔʁ <button id=“add-item”>Ճ</a>
Ͳ͜Ͱॲཧ͢Δ͔ ͔Βͳ͍ <div id=“item-1”> <span id=“item-1-text”>foo</span> </div> ͍ͭͲ͜Ͱॻ͖͑Δͷ͔ ͔Βͳ͍
DOMૢ࡞ͳ͍ͥ͠ͷ͔ <div id=“item-1”> <span id=“item-1-text” class=“hidden”>foo</span> </div> ͜ͷλάݟ͑ͯΔʁ <button id=“add-item”>Ճ</a>
Ͳ͜Ͱॲཧ͢Δ͔ ͔Βͳ͍ <div id=“item-1”> <span id=“item-1-text”>foo</span> </div> ͍ͭͲ͜Ͱॻ͖͑Δͷ͔ ͔Βͳ͍ DOMͲ͔͜ΒͰมߋՄೳ DOM͕ঢ়ଶΛ͍࣋ͬͯΔ DOMͱίʔυ͕Ε͗͢
ͬͱ؆୯ʹΖ͏ DOMΛॻ͖͑ͳ͍ͰৗʹHTMLશମΛੜ EventListenerΛΊͯonXxxϓϩύςΟΛ͏ HTMLͱJavascriptΛҰͭʹ·ͱΊΔ
ΫϥΠΞϯτϩδοΫ αʔόαΠυੜ ϒϥβ ϩδοΫ (ίϯτϩʔϥ) ϦΫΤετ αʔό ΫϥΠΞϯτ HTMLੜ෦ (render)
HTMLੜ෦ (ςϯϓϨʔτ) ը໘Λදࣔ͢ΔͨΊͷঢ়ଶ (setState) ը໘Λදࣔ͢ΔͨΊͷঢ়ଶ (ςϯϓϨʔτม)
ΫϥΠΞϯτϩδοΫ ϒϥβ αʔό ΫϥΠΞϯτ Πϕϯτ (onSubmit) React.js αʔόϩδοΫ HTMLੜ෦ (render)
ը໘Λදࣔ͢ΔͨΊͷঢ়ଶ (setState)
Example: Todo list http://codepen.io/masuidrive
P.1 - ྻͷΞΠςϜΛදࣔ
/** @jsx React.DOM */ App = React.createClass({ getInitialState: function() {
return { items: [ { text: "Foo" }, { text: "Bar" }, { text: "Buzz" } ] }; }, render: function() { return <div> <div> {this.state.items.map(function(item) { return <div className="item">{item.text}</div>; })} </div> </div>; } }); React.render(<App/>, document.body); P.1 - ྻͷΞΠςϜΛදࣔ
P.2 - ΞΠςϜΛՃ
/** @jsx React.DOM */ App = React.createClass({ getInitialState: function() {
return { newText: "", items: [ { text: "Foo" }, { text: "Bar" }, { text: "Buzz" } ] }; }, addItem: function(event) { event.preventDefault(); this.setState({ items: [{text : this.state.newText}].concat(this.state.items), newText: "" }) }, updateNewText: function(event) { this.setState({ newText : event.target.value }); }, render: function() { return <div> <form onSubmit={this.addItem}> <input value={this.state.newText} onChange={this.updateNewText} /> <button>Ճ</button> </form> ɹ <div> {this.state.items.map(function(item) { return <div className="item">{item.text}</div>; })} </div> </div>; } }); React.render(<App/>, document.body); P.2 - ΞΠςϜΛՃ
addItem: function(event) { event.preventDefault(); this.setState({ items: [{text : this.state.newText}].concat(this.state.items), newText:
"" }) }, updateNewText: function(event) { this.setState({ newText : event.target.value }); }, render: function() { return <div> <form onSubmit={this.addItem}> <input value={this.state.newText} onChange={this.updateNewText} /> <button>Ճ</button> </form> ɹ <div> {this.state.items.map(function(item) { ← 1จࣈೖྗͷͨͼʹݺΕΔ P.2 - ΞΠςϜΛՃ
P.3 - ݅දࣔ ݅ →
P.3 - ݅දࣔ /** @jsx React.DOM */ App = React.createClass({
getInitialState: function() { return { newText: "", items: [ { text: "Foo" }, { text: "Bar" }, { text: "Buzz" } ] }; }, addItem: function() { event.preventDefault(); this.setState({ items: [{text : this.state.newText}].concat(this.state.items), newText: "" }) }, updateNewText: function(ev) { this.setState({ newText : ev.target.value }); }, render: function() { return <div> <form onSubmit={this.addItem}> <input value={this.state.newText} onChange={this.updateNewText} /> <button>Ճ</button> </form> <div>{this.state.items.length}݅</div> <div> {this.state.items.map(function(item) { return <div className="item">{item.text}</div>; })} </div> </div>; } }); React.render(<App/>, document.body);
P.3 - ݅දࣔ }); }, render: function() { return <div>
<form onSubmit={this.addItem}> <input value={this.state.newText} onChange={this.updateNewText} /> <button>Ճ</button> </form> <div>{this.state.items.length}݅</div> <div> {this.state.items.map(function(item) { return <div className="item">{item.text}</div>; })} </div> </div>; } }); React.render(<App/>, document.body);
HTMLΛৗʹ࠶ߏங͢Δ͜ͱͰ ঢ়ଶม ϩδοΫ มΛߋ৽ Ϗϡʔ ม͔Βੜ
Ͱ… • HTMLશମॻ͖͑Δͱ͘ͳ͍ʁ • CSSΞχϝʔγϣϯ͑ͳ͍ΑͶʁ • ࣮ຊޠೖྗͰ͖ͳ͍ΑͶ
<div> <div>3݅</div> <div className=“items”> <div className=“item”> Foo </div> <div className=“item”>
Bar </div> <div className=“item”> Buzz </div> </div> <div> ݱࡏͷDOM ࣮ࡍͷߋ৽ VirtualDOM BrowserDOM ৽͍͠DOM <div> <div>4݅</div> <div className=“item”> <div className=“item”> Foo </div> <div className=“item”> Bar </div> <div className=“item”> Buzz </div> <div className=“item”> One </div> </div> <div> (ͨͩͷJS Object) <div> <div>4݅</div> <div class=“item”> <div class=“item”> Foo </div> <div class=“item”> Bar </div> <div class=“item”> Buzz </div> <div class=“item”> One </div> </div> <div>
<div> <div>3݅</div> <div className=“items”> <div className=“item”> Foo </div> <div className=“item”>
Bar </div> <div className=“item”> Buzz </div> </div> <div> ݱࡏͷDOM ࣮ࡍͷߋ৽ VirtualDOM BrowserDOM ৽͍͠DOM <div> <div>4݅</div> <div className=“item”> <div className=“item”> Foo </div> <div className=“item”> Bar </div> <div className=“item”> Buzz </div> <div className=“item”> One </div> </div> <div> (ͨͩͷJS Object) <div> <div>4݅</div> <div class=“item”> <div class=“item”> Foo </div> <div class=“item”> Bar </div> <div class=“item”> Buzz </div> <div class=“item”> One </div> </div> <div>
ͬͱٕज़తʹ • key • component • property • dangerouslySetInnerHTML •
ৄ͘͠άά͍ͬͯͩ͘͞
͞Βʹ • ComponentͰ࠶ར༻Մೳͳ෦Խ • αʔόαΠυϨϯμϦϯά • ͬͱେ͖ͳΞϓϦͰFlux • iOS/AndroidΞϓϦReactNative
• ίʔυΛॻ͘ਓ͕HTMLॻ͘ • طଘͷJS෦͕͑ͳ͍(͜ͱͳ͍) • ಛʹTwitter Widgetͱ͔֎෦JSۤख
Flux • ߟ͑ํͷ໊લ (MVCͱ͔ͱҰॹ) • ReactͰData͑͞มߋ͢Εը໘ʹө͞ΕΔ • Ϣʔβ͔ΒͷActionΛݩʹDispatcher͕Storeͷ มߋΛݺͼग़͢
Dispatcher Action Store React User action
Dispatcher Action Store React User action render: function() { return
<header id="header"> <h1>todos</h1> <TodoTextInput id="new-todo" placeholder="What needs to be done?" onSave={this._onSave} /> </header>; }, _onSave: function(text) { if(text.trim()) { TodoActions.create(text) } } components/Header.js
Dispatcher Action Store React User action actions/TodoActions.js TodoActions = {
create: function(text) { AppDispatcher.dispatch({ actionType: TodoConst.TODO_CREATE, text: text }); } }
Dispatcher Action Store React User action stores/TodoStore.js AppDispatcher.register(function(action) { switch(action.actionType)
{ case TodoConst.TODO_CREATE: create(action.text); TodoStore.emit(“change”); } }); function create() { var id = Math.random(); _todos[id] = { id: id complete: false text: text }; }
Dispatcher Action Store React User action components/TodoApp.js var TodoApp =
React.createClass({ getInitialState: function() { return({ todos: TodoStore.getAll() }); }, componentDidMount: function() { TodoStore.addListener(this._onChange); }, _onChange: function() { this.setState({todos: TodoStore.getAll()}); }, render: function() { return ... } });
·ͱΊ • αʔόαΠυͷ༷ͳγϯϓϧͳྲྀΕͰAjaxΛ • ը໘Λॻ͖͑Δͱ͖ৗʹશ෦ॻ͖͑ • طଘͷJS UIϥΠϒϥϦͱಉډ͍͠