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 Presentation
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
vjeux
June 25, 2013
Programming
14k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React Presentation
https://twitter.com/renajohn/status/349103656571904000
vjeux
June 25, 2013
More Decks by vjeux
See All by vjeux
React Rally: Animated -- React Performance Toolbox
vjeux
84
91k
React: CSS in JS - React France Meetup
vjeux
33
12k
React: CSS in JS
vjeux
657
1.5M
OSCON - React Architecture
vjeux
111
45k
Why does React scale? - JSConf 2014
vjeux
52
2M
Image Layout Algorithms - HTML5 Dev Conf
vjeux
13
860k
Image Layout Algorithms
vjeux
5
820
Generic Image Processing With Climb – 5th ELS
vjeux
1
6k
Climb - A Generic and Dynamic Approach to Image Processing
vjeux
1
3.3k
Other Decks in Programming
See All in Programming
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
710
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
190
A2UI という光を覗いてみる
satohjohn
1
130
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
260
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
Oxlintのカスタムルールの現況
syumai
6
1.1k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
500
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
530
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
420
Evolving SEO for Evolving Search Engines
ryanjones
0
210
sira's awesome portfolio website redesign presentation
elsirapls
0
280
We Have a Design System, Now What?
morganepeng
55
8.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
420
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Odyssey Design
rkendrick25
PRO
2
690
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Transcript
Facebook React http://facebook.github.io/react/index.html Renault John Lecoultre @renajohn
[email protected]
Disclaimer There will be in this presentation
React is a JavaScript library to build reusable UI components
React is used in production Main page Some parts
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1 Component render function
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1 Inject component in DOM
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1 Access component properties (attributes and childern)
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Example 1
is not strictly mandatory var HelloMessage = React.createClass({ render: function()
{ return React.DOM.div({}, 'Hello ' + this.props.name}); } }); React.renderComponent( HelloMessage({ name: "JS Romandie" }), document.body );
is not strictly mandatory var HelloMessage = React.createClass({ render: function()
{ return React.DOM.div({}, 'Hello ' + this.props.name}); } }); React.renderComponent( HelloMessage({ name: "JS Romandie" }), document.body );
is not strictly mandatory var HelloMessage = React.createClass({ render: function()
{ return React.DOM.div({}, 'Hello ' + this.props.name}); } }); React.renderComponent( HelloMessage({ name: "JS Romandie" }), document.body );
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body );
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body ); Import all HTML elements as React components
React is declarative /** @jsx React.DOM */ var HelloMessage =
React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent( <HelloMessage name="JS Romandie" />, document.body );
Components are composable /** @jsx React.DOM */ var Message =
React.createClass({ render: function() { return <span> {this.props.text + " "}</span>; } }); var HelloFullName = React.createClass({ render: function() { return <div> <Message text=”Hello”/> <Message text= {this.props.firstName} /> <Message text= {this.props.firstName} /> </div>; } }); React.renderComponent( <HelloFullName firstName="JS" lastName="Romandie"/>, document.body );
Components are composable /** @jsx React.DOM */ var Message =
React.createClass({ render: function() { return <span> {this.props.text + " "}</span>; } }); var HelloFullName = React.createClass({ render: function() { return <div> <Message text=”Hello”/> <Message text= {this.props.firstName} /> <Message text= {this.props.firstName} /> </div>; } }); React.renderComponent( <HelloFullName firstName="JS" lastName="Romandie"/>, document.body );
Components are composable /** @jsx React.DOM */ var Message =
React.createClass({ render: function() { return <span> {this.props.text + " "}</span>; } }); var HelloFullName = React.createClass({ render: function() { return <div> <Message text=”Hello”/> <Message text= {this.props.firstName} /> <Message text= {this.props.firstName} /> </div>; } }); React.renderComponent( <HelloFullName firstName="JS" lastName="Romandie"/>, document.body );
var Timer = React.createClass({ }); React.renderComponent(Timer({}), document.body); React components are
stateful
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); React components are stateful
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); React components are stateful Defined initial state. Called just once per component
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); React components are stateful Retrieve component state
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); React components are stateful
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, tick: React.autoBind(function() { this.setState({secondsElapsed: this.state.secondsElapsed + 1}); }), componentDidMount: function() { setInterval(this.tick, 1000); }, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); Example 2 React components are stateful
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, tick: React.autoBind(function() { this.setState({secondsElapsed: this.state.secondsElapsed + 1}); }), componentDidMount: function() { setInterval(this.tick, 1000); }, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); Example 2 React components are stateful Always use setState when changing state
var Timer = React.createClass({ getInitialState: function() { return {secondsElapsed: 0};
}, tick: React.autoBind(function() { this.setState({secondsElapsed: this.state.secondsElapsed + 1}); }), componentDidMount: function() { setInterval(this.tick, 1000); }, render: function() { return React.DOM.div({}, 'Seconds Elapsed: ' + this.state.secondsElapsed ); } }); React.renderComponent(Timer({}), document.body); Example 2 React components are stateful
No update function • When state changes, the view is
re-rendered • React figures out the smallest DOM mutation
React reconciliation /** @jsx React.DOM */ var TextBoxList = React.createClass({
getInitialState: function() { return {count: 1}; }, add: React.autoBind(function() { this.setState({count: this.state.count + 1}); }), render: function() { var items = []; for (var i = 0; i < this.state.count; i++) { items.push( <li><input type="text" placeholder="change me!" /></li> ); } return ( <ul> {items} <input type="button" value="Add something" onClick={this.add}/> </ul> ); } }); Example 3
Pitfalls It’s XML! Element have to be balanced: <br> →
<br /> <img src=”...”> → <img src=”...” />
Pitfalls Render function should return only one node: render: function()
{ return <i class=”icon-trash”></i> delete; }
Pitfalls Render function should return only one node: render: function()
{ return <i class=”icon-trash”></i> delete; } Wrong
Pitfalls Render function should return only one node: render: function()
{ return <i class=”icon-trash”></i> delete; } Wrong render: function() { return <div><i class=”icon-trash”></i> delete</div>; } OK
React tutorial • Optimistic commenting: comments appear in the list
before they're saved on the server so it feels fast. • Live updates: new comments appears in real time • Markdown formatting: users can use Markdown to format their text Building a commenting widget Demo
Thank you Renault John Lecoultre
[email protected]