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
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
830
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
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
Performance Engineering for Everyone
elenatanasoiu
0
250
act1-costs.pdf
sumedhbala
0
150
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
1
540
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.6k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.4k
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.6k
Contextとはなにか
chiroruxx
1
390
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
230
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.6k
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
0
9.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The agentic SEO stack - context over prompts
schlessera
0
840
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Agile that works and the tools we love
rasmusluckow
331
22k
Designing Powerful Visuals for Engaging Learning
tmiket
1
430
What's in a price? How to price your products and services
michaelherold
247
13k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Are puppies a ranking factor?
jonoalderson
1
3.7k
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]