SlideShare a Scribd company logo
Ben Newman (@benjamn)
Paul O’Shannessy (@zpao)
React
reactjs.org
Components
<div>, <span>
<ActionButton>, <Counter>
Anatomy of a Component
<ActionButton text="Book flight" onAction={someFunc} />
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
!
!
!
!
!
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
!
!
!
!
!
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton">	
<span>button text</span>	
</button>	
);	
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton">	
<span>{this.props.text}</span>	
</button>	
);	
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton" onClick={this.props.onAction}>	
<span>{this.props.text}</span>	
</button>	
);	
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton" onClick={this.props.onAction}>	
<span>{this.props.text}</span>	
</button>	
);	
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton" onClick={this.props.onAction}>	
<span>{this.props.text.toUpperCase()}</span>	
</button>	
);	
}	
});
<ActionButton text="Book flight" onAction={someFunc} />
var ActionButton = React.createClass({	
render: function() {	
return (	
<button class="ActionButton" onClick={this.props.onAction}>	
<span>{this.props.text}</span>	
</button>	
);	
}	
});
<Counter initialCount={4} />
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
What makes React different?
1. Components, not templates
2. Re-render on update
3. Virtual DOM (and events)
1. Components, not templates
Separation of
concerns:
!
Reduce coupling, increase cohesion.
Coupling is:
“The degree to which each program
module relies on each of the other
modules.”
http://en.wikipedia.org/wiki/Coupling_(computer_science)
Cohesion is:
“The degree to which elements of a
module belong together.”
http://en.wikipedia.org/wiki/Cohesion_(computer_science)
“View model” tightly
couples template to
display logic.
[{“price”: “7.99”, “product”: “Back
scratcher”, “tableRowColor”: “rgba(0, 0, 0,
0.5)”}]
Templates separate
technologies, not
concerns
React components are loosely
coupled and highly cohesive
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
2. Re-render on every change
<Counter initialCount={4} />
var Counter = React.createClass({	
getInitialState: function() {	
return {count: this.props.initialCount};	
},	
addToCount: function(delta) {	
this.setState({count: this.state.count + delta})	
},	
render: function() {	
return (	
<div>	
<h3>Count: {this.state.count}</h3>	
<ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} />	
<ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} />	
</div>	
);	
}	
});
- no DOM mutations
- no bindings between data and DOM
- in general, way less shit to think about
Best analogy: Website from 1994
Data changing over time is the
root of all evil.
Re-rendering on
every change makes
things simple.
Every place data is displayed is guaranteed
to be up-to-date.
No magical data binding.
Re-rendering on
every change makes
things simple.
No model dirty checking.
Re-rendering on
every change makes
things simple.
No more explicit DOM operations –
everything is declarative.
Re-rendering on
every change makes
things simple.
3. Virtual DOM
Won’t rerendering be as slow as
molasses?!
React has a virtual DOM (and
events system).
Optimized for performance and
memory footprint
On every update…
• React builds a new virtual DOM
subtree
• …diffs it with the old one
• …computes the minimal set of DOM
mutations and puts them in a queue
• …and batch executes all updates
It’s fast!
Because the DOM is slow!
It’s fast!
Computes minimal DOM operations
It’s fast!
Batched reads and writes for optimal DOM
performance
It’s fast!
Usually faster than manual DOM
operations
It’s fast!
Automatic top-level event delegation (with
cross-browser HTML5 events)
It’s fast!
Can do all this at 60fps, even in a (non-JIT)
UIWebView on the iPhone.
Why Should YOU Use React?
• Can be used for parts of your application
• Plays well with other libraries and technologies

(meteor, rails, node)
• Components allow you to split work easily
Learn more and get involved
• http://reactjs.org
• #reactjs on Freenode IRC
• reactjs on Google Groups
• www.facebook.com/careers
More Links
• react-meteor: https://github.com/benjamn/react-meteor
• <ActionButton> demo: http://jsfiddle.net/zpao/EFhy4/
• <Clicker> demo: http://jsfiddle.net/zpao/fk5Pc/
ReactJS

More Related Content

What's hot

React.js & Om: A hands-on walkthrough of better ways to build web UIs
React.js & Om: A hands-on walkthrough of better ways to build web UIsReact.js & Om: A hands-on walkthrough of better ways to build web UIs
React.js & Om: A hands-on walkthrough of better ways to build web UIs
Adam Solove
 
React
React React
React
중운 박
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
Ali Sa'o
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
Maksym Petruk
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
Domenic Denicola
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
nishasowdri
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
React Lifecycle and Reconciliation
React Lifecycle and ReconciliationReact Lifecycle and Reconciliation
React Lifecycle and Reconciliation
Zhihao Li
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
Eldar Djafarov
 
React & redux
React & reduxReact & redux
React & redux
Cédric Hartland
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
Uldis Sturms
 
Avoiding callback hell with promises
Avoiding callback hell with promisesAvoiding callback hell with promises
Avoiding callback hell with promises
TorontoNodeJS
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
Vinícius Ribeiro
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
Simon Sturmer
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
Tomasz Bak
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
Harvard Web Working Group
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
Eugene Zharkov
 

What's hot (20)

React.js & Om: A hands-on walkthrough of better ways to build web UIs
React.js & Om: A hands-on walkthrough of better ways to build web UIsReact.js & Om: A hands-on walkthrough of better ways to build web UIs
React.js & Om: A hands-on walkthrough of better ways to build web UIs
 
React
React React
React
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
React Lifecycle and Reconciliation
React Lifecycle and ReconciliationReact Lifecycle and Reconciliation
React Lifecycle and Reconciliation
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
 
React & redux
React & reduxReact & redux
React & redux
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Avoiding callback hell with promises
Avoiding callback hell with promisesAvoiding callback hell with promises
Avoiding callback hell with promises
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 

Viewers also liked

ReactJs
ReactJsReactJs
ReactJs
LearningTech
 
ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는
Taegon Kim
 
Datomic – A Modern Database - StampedeCon 2014
Datomic – A Modern Database - StampedeCon 2014Datomic – A Modern Database - StampedeCon 2014
Datomic – A Modern Database - StampedeCon 2014
StampedeCon
 
Probability with Cards
Probability with CardsProbability with Cards
Probability with Cards
ianrhunter
 
Unity 5: First-Person Tutorial
Unity 5: First-Person TutorialUnity 5: First-Person Tutorial
Unity 5: First-Person Tutorial
Shahed Chowdhuri
 
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
DataStax
 
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
Kai Wähner
 
Elon Musk and his innovations
Elon Musk and his innovationsElon Musk and his innovations
Elon Musk and his innovations
Rohan Bharaj
 
19 Mini Productivity Hacks For A Simple (But An Awesome) Day
19 Mini Productivity Hacks For A Simple (But An Awesome) Day19 Mini Productivity Hacks For A Simple (But An Awesome) Day
19 Mini Productivity Hacks For A Simple (But An Awesome) Day
Thomas Oppong
 
Inside BCG's Smart Simplicity Approach
Inside BCG's Smart Simplicity ApproachInside BCG's Smart Simplicity Approach
Inside BCG's Smart Simplicity Approach
Boston Consulting Group
 
Entrepreneur Elon musk
Entrepreneur   Elon muskEntrepreneur   Elon musk
Entrepreneur Elon musk
Shashank Tiwari
 
Bill gates powerpoint
Bill gates powerpointBill gates powerpoint
Bill gates powerpointmasonwilson1
 
Leadership by Elon Musk with Tesla and SpaceX
Leadership by Elon Musk with Tesla and SpaceXLeadership by Elon Musk with Tesla and SpaceX
Leadership by Elon Musk with Tesla and SpaceX
Saptu Ray
 
Bill gates leadership & personality traits
Bill gates leadership & personality traitsBill gates leadership & personality traits
Bill gates leadership & personality traitsAkhil Pillai
 
Elon Musk- Visionary, Leader, Entrepreneur
Elon Musk- Visionary, Leader, EntrepreneurElon Musk- Visionary, Leader, Entrepreneur
Elon Musk- Visionary, Leader, Entrepreneur
Muhtasim Sarowat Rayed
 
Smart Cities – how to master the world's biggest growth challenge
Smart Cities – how to master the world's biggest growth challengeSmart Cities – how to master the world's biggest growth challenge
Smart Cities – how to master the world's biggest growth challenge
Boston Consulting Group
 
Datomic
DatomicDatomic
Datomic
Jordan Leigh
 
Datomic
DatomicDatomic
Datomic
DatomicDatomic
Datomic
jperkelens
 
Waldorf Education
Waldorf EducationWaldorf Education
Waldorf Education
xMerodi
 

Viewers also liked (20)

ReactJs
ReactJsReactJs
ReactJs
 
ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는ReactJS | 서버와 클라이어트에서 동시에 사용하는
ReactJS | 서버와 클라이어트에서 동시에 사용하는
 
Datomic – A Modern Database - StampedeCon 2014
Datomic – A Modern Database - StampedeCon 2014Datomic – A Modern Database - StampedeCon 2014
Datomic – A Modern Database - StampedeCon 2014
 
Probability with Cards
Probability with CardsProbability with Cards
Probability with Cards
 
Unity 5: First-Person Tutorial
Unity 5: First-Person TutorialUnity 5: First-Person Tutorial
Unity 5: First-Person Tutorial
 
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
Fast, In-Memory SQL on Apache Cassandra with Apache Ignite (Rachel Pedreschi,...
 
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
Real World Use Cases and Success Stories for In-Memory Data Grids (TIBCO Acti...
 
Elon Musk and his innovations
Elon Musk and his innovationsElon Musk and his innovations
Elon Musk and his innovations
 
19 Mini Productivity Hacks For A Simple (But An Awesome) Day
19 Mini Productivity Hacks For A Simple (But An Awesome) Day19 Mini Productivity Hacks For A Simple (But An Awesome) Day
19 Mini Productivity Hacks For A Simple (But An Awesome) Day
 
Inside BCG's Smart Simplicity Approach
Inside BCG's Smart Simplicity ApproachInside BCG's Smart Simplicity Approach
Inside BCG's Smart Simplicity Approach
 
Entrepreneur Elon musk
Entrepreneur   Elon muskEntrepreneur   Elon musk
Entrepreneur Elon musk
 
Bill gates powerpoint
Bill gates powerpointBill gates powerpoint
Bill gates powerpoint
 
Leadership by Elon Musk with Tesla and SpaceX
Leadership by Elon Musk with Tesla and SpaceXLeadership by Elon Musk with Tesla and SpaceX
Leadership by Elon Musk with Tesla and SpaceX
 
Bill gates leadership & personality traits
Bill gates leadership & personality traitsBill gates leadership & personality traits
Bill gates leadership & personality traits
 
Elon Musk- Visionary, Leader, Entrepreneur
Elon Musk- Visionary, Leader, EntrepreneurElon Musk- Visionary, Leader, Entrepreneur
Elon Musk- Visionary, Leader, Entrepreneur
 
Smart Cities – how to master the world's biggest growth challenge
Smart Cities – how to master the world's biggest growth challengeSmart Cities – how to master the world's biggest growth challenge
Smart Cities – how to master the world's biggest growth challenge
 
Datomic
DatomicDatomic
Datomic
 
Datomic
DatomicDatomic
Datomic
 
Datomic
DatomicDatomic
Datomic
 
Waldorf Education
Waldorf EducationWaldorf Education
Waldorf Education
 

Similar to ReactJS

React 101
React 101React 101
React 101
Casear Chu
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
Boris Dinkevich
 
Full Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R StackFull Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R Stack
Scott Persinger
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
Younes (omar) Meliani
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Learning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User InterfacesLearning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User Interfaces
Ken Wheeler
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
Adam L Barrett
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
Anjali Chawla
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
Ignacio Martín
 
How do we use hooks
How do we use hooksHow do we use hooks
How do we use hooks
Jim Liu
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
Ignacio Martín
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extensionHendy Irawan
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
jeresig
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
BOSC Tech Labs
 
Client Web
Client WebClient Web
Client Web
Markiyan Matsekh
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react application
Greg Bergé
 
Redux js
Redux jsRedux js
Redux js
Nils Petersohn
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 

Similar to ReactJS (20)

React 101
React 101React 101
React 101
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
 
Full Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R StackFull Stack Toronto - the 3R Stack
Full Stack Toronto - the 3R Stack
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Learning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User InterfacesLearning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User Interfaces
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
How do we use hooks
How do we use hooksHow do we use hooks
How do we use hooks
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extension
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Client Web
Client WebClient Web
Client Web
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react application
 
Redux js
Redux jsRedux js
Redux js
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 

More from Kamlesh Singh

Angular js book
Angular js bookAngular js book
Angular js book
Kamlesh Singh
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle BasicKamlesh Singh
 

More from Kamlesh Singh (8)

Angular js book
Angular js bookAngular js book
Angular js book
 
Smart machines
Smart machinesSmart machines
Smart machines
 
Spring roo-docs
Spring roo-docsSpring roo-docs
Spring roo-docs
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle Basic
 
Oops Concept Java
Oops Concept JavaOops Concept Java
Oops Concept Java
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
 
Jvm
JvmJvm
Jvm
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

ReactJS

  • 1.
  • 2. Ben Newman (@benjamn) Paul O’Shannessy (@zpao) React reactjs.org
  • 4. Anatomy of a Component
  • 5. <ActionButton text="Book flight" onAction={someFunc} />
  • 6. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { ! ! ! ! ! } });
  • 7. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { ! ! ! ! ! } });
  • 8. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton"> <span>button text</span> </button> ); } });
  • 9. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton"> <span>{this.props.text}</span> </button> ); } });
  • 10. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton" onClick={this.props.onAction}> <span>{this.props.text}</span> </button> ); } });
  • 11. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton" onClick={this.props.onAction}> <span>{this.props.text}</span> </button> ); } });
  • 12. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton" onClick={this.props.onAction}> <span>{this.props.text.toUpperCase()}</span> </button> ); } });
  • 13. <ActionButton text="Book flight" onAction={someFunc} /> var ActionButton = React.createClass({ render: function() { return ( <button class="ActionButton" onClick={this.props.onAction}> <span>{this.props.text}</span> </button> ); } });
  • 15. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 16. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 17. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 18. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 19. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 20. What makes React different?
  • 21. 1. Components, not templates 2. Re-render on update 3. Virtual DOM (and events)
  • 22.
  • 23.
  • 24. 1. Components, not templates
  • 26. Coupling is: “The degree to which each program module relies on each of the other modules.” http://en.wikipedia.org/wiki/Coupling_(computer_science)
  • 27. Cohesion is: “The degree to which elements of a module belong together.” http://en.wikipedia.org/wiki/Cohesion_(computer_science)
  • 28. “View model” tightly couples template to display logic. [{“price”: “7.99”, “product”: “Back scratcher”, “tableRowColor”: “rgba(0, 0, 0, 0.5)”}]
  • 30. React components are loosely coupled and highly cohesive
  • 31. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } });
  • 32. 2. Re-render on every change
  • 33. <Counter initialCount={4} /> var Counter = React.createClass({ getInitialState: function() { return {count: this.props.initialCount}; }, addToCount: function(delta) { this.setState({count: this.state.count + delta}) }, render: function() { return ( <div> <h3>Count: {this.state.count}</h3> <ActionButton text="+1" onAction={this.addToCount.bind(this, 1)} /> <ActionButton text="-1" onAction={this.addToCount.bind(this, -1)} /> </div> ); } }); - no DOM mutations - no bindings between data and DOM - in general, way less shit to think about
  • 35. Data changing over time is the root of all evil.
  • 36. Re-rendering on every change makes things simple. Every place data is displayed is guaranteed to be up-to-date.
  • 37. No magical data binding. Re-rendering on every change makes things simple.
  • 38. No model dirty checking. Re-rendering on every change makes things simple.
  • 39. No more explicit DOM operations – everything is declarative. Re-rendering on every change makes things simple.
  • 41. Won’t rerendering be as slow as molasses?!
  • 42. React has a virtual DOM (and events system). Optimized for performance and memory footprint
  • 43. On every update… • React builds a new virtual DOM subtree • …diffs it with the old one • …computes the minimal set of DOM mutations and puts them in a queue • …and batch executes all updates
  • 44. It’s fast! Because the DOM is slow!
  • 46. It’s fast! Batched reads and writes for optimal DOM performance
  • 47. It’s fast! Usually faster than manual DOM operations
  • 48. It’s fast! Automatic top-level event delegation (with cross-browser HTML5 events)
  • 49. It’s fast! Can do all this at 60fps, even in a (non-JIT) UIWebView on the iPhone.
  • 50. Why Should YOU Use React? • Can be used for parts of your application • Plays well with other libraries and technologies
 (meteor, rails, node) • Components allow you to split work easily
  • 51. Learn more and get involved • http://reactjs.org • #reactjs on Freenode IRC • reactjs on Google Groups • www.facebook.com/careers
  • 52. More Links • react-meteor: https://github.com/benjamn/react-meteor • <ActionButton> demo: http://jsfiddle.net/zpao/EFhy4/ • <Clicker> demo: http://jsfiddle.net/zpao/fk5Pc/