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
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
220
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.6k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
530
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
200
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
6
4k
ふつうのFeature Flag実践入門
irof
7
3.7k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
1.2k
3Dシーンの圧縮
fadis
1
730
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
500
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
420
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
230
Building Flexible Design Systems
yeseniaperezcruz
330
40k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
320
Optimising Largest Contentful Paint
csswizardry
37
3.7k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Statistics for Hackers
jakevdp
799
230k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
The untapped power of vector embeddings
frankvandijk
2
1.8k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
Embracing the Ebb and Flow
colly
88
5.1k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
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]