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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
54
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
540
トレタの存在理由
masuidrive
0
250
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.4k
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
120
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
210
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
220
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
dRuby over BLE
makicamel
2
400
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
170
Datadog LLM Observabilityで実現する 安全なLLM Usage 管理
3150
0
130
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
810
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
220
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
310
Featured
See All Featured
The SEO Collaboration Effect
kristinabergwall1
1
490
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
We Are The Robots
honzajavorek
0
260
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
A designer walks into a library…
pauljervisheath
211
24k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
320
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
250
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
630
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ϥΠϒϥϦͱಉډ͍͠