SlideShare a Scribd company logo
1 of 97
Download to read offline
An introduction to
React.js
Emanuele DelBono - @emadb
Community Days 2015
History of front-end development…
MV* in the browser
Enterprise Javascript
Quickly became the de-facto standard
Quiz time!
What’s the difference between
Service, Factory, Provider?
How many option do you
have with ng-class?
Full & Heavy
Full framework
Ajax
Routing
Binding
Modules
#CDays15 – Milano 24, 25 e 26 Marzo 2015
Grazie a
Pla$num(
Sponsor(
Who I am
A superhero?
Who I am
A software developer.
Passionated about his
job.
MVC? No, only the V
People think that
React.js is awesome
Not a new idea…
Hello React
var MyComponent = React.createClass({
render: function() {
return (
<h1>Hello React</h1>
);
}
});
React.render(
<MyComponent />,
document.body);
WHAT LANGUAGE IS
THAT?
JSX
JSX lets you create JavaScript objects using
HTML syntax
It’s optional…but once you get used to is very
helpful
Markup with code?
var MyComponent = React.createClass({
displayName: "MyComponent",
render: function() {
return (
React.createElement("h1", null, "Hello React")
);
}
});
React.render(
React.createElement(MyComponent, null),
document.body);
Markup with code?
“Markup and display logic both share
the same concern”
Pete Hunt
Everything is a
component
• HTML is defined inside the component
• Component logic
• State is private
• Support parameters
• Events or callback for communication
var Title = React.createClass({
render: function() {
return (
<h1>Hello React</h1>
);
}
});
var SubTitle = React.createClass({
render: function() {
return (
<h3>A library for web components</h3>
);
}
});
var Container = React.createClass({
render: function() {
return (
<div>
<Title>
<SubTitle>
</div>
);
}
});
Properties
• Values can be passed to the component as
parameters
• Should be immutable
• Useful for passing callback (from parent to
child)
var Container = React.createClass({
render: function() {
return (
<div>
<Title text="Hello react"/>
<SubTitle text="A library for web components"/>
</div>
);
}
});
var Title = React.createClass({
render: function() {
return (
<h1>{this.props.text}</h1>
);
}
});
var SubTitle = React.createClass({
render: function() {
return (
<h3>{this.props.text}</h3>
);
}
});
var Container = React.createClass({
render: function(){
return (
<div>
<h2> Some title </h2>
{this.props.children}
</div>);
}
});
var Panel = React.createClass({
render: function(){
return (
<Container>
<div>child one</div>
<div>child two</div>
</Container>);
}
});
State
• State is private and represent the internal
situation
• State can change using provided methods
var Container = React.createClass({
getInitialState: function(){
return { title: this.props.title, newTitle: 'new title' }
},
handleClick: function(){
this.setState({title: this.state.newTitle});
},
handleChg: function(event) {
this.setState({newTitle: event.target.value});
},
render: function() {
return (
<div>
<h1>{this.state.title}</h1>
<input type="text" value={this.state.newTitle} onChange={this.handleChg}/>
<button onClick={this.handleClick}>Change title</button>
</div>
);
}
});
RENDER IS CALLED
EVERY TIME THE STATE
CHANGE!
OMG
Virtual DOM
Javascript that access to the DOM is slow
console.dir(document.createElement('div'));
A DIV contains about 135 first level properties/function
(700 on second level).
A virtual DOM div element contains only 6 properties.
Virtual DOM
• Our code act on a fake DOM
• React.js takes care of generating a DOM patch
to update the real DOM
• Every ReactElement is a light, stateless,
immutable, virtual representation of a DOM
Element
Double Buffering
var ClickCounter = React.createClass({
getInitialState: function(){
console.log('getInitialState');
return {count: 0};
},
handleClick: function(){
console.log('handleClick');
this.setState({count: ++this.state.count});
},
render: function() {
console.log('rendering....');
return (
<div>
<button onClick={this.handleClick}>+</button>
<span> {this.state.count} </span>
</div>
);
}
});
WHAT
ABOUT BIG
APPS?
Component lifecycle
getDefaultProps
getInitialState
componentWillMount
render
componentDidMount
Architecture guidelines
Flux: React Views
• The react component that we have just seen
• They receive commands from the user and
send actions
Flux: React Views
Store
React View
State
Flux: Actions and
ActionCreators
• ActionCreators creates actions
• Communicate with the external API
• Dispatch the actions
Flux: React Actions
ActionCreatorReact View
Dispatcher
Action
API
Flux: Dispachter
• Dispatch actions to the subscribers
Flux: Dispatcher
Store
Action
Dispatcher
Store Store
Flux: Store
• Manages application state
• Receives messages from the Dispatcher
• Notify views for changes
Flux: Store
Store
React View
Dispatcher
Change
event
Request
new state
How does it feel?
Browserify/Webpack
Modules done right (in the browser)
More here…
https://github.com/facebook/react/wiki/Complementary-Tools
https://github.com/enaqx/awesome-react
More topics…
PropTypes for validation
Minxin for extensibility
Server side rendering
Synthetic events
Inline style
React Native
<Thankyou />
@emadb
http://ema.codiceplastico.com
#CDays14 – Milano 25, 26 e 27 Febbraio 2014
Q&A
Tu#o%il%materiale%di%questa%sessione%su%
h#p://www.communitydays.it/%%
%
Lascia%subito%il%feedback%su%questa%sessione,%
potrai%essere%estra#o%per%i%nostri%premi!%
%
Seguici%su%
%Twi#er%@CommunityDaysIT%
%Facebook%h#p://facebook.com/cdaysit%
%#CDays15%

More Related Content

What's hot

[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 

What's hot (20)

React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
React JS
React JSReact JS
React JS
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
reactJS
reactJSreactJS
reactJS
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
ReactJs
ReactJsReactJs
ReactJs
 
React js
React jsReact js
React js
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
ReactJS
ReactJSReactJS
ReactJS
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
React js basics
React js basicsReact js basics
React js basics
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React workshop
React workshopReact workshop
React workshop
 

Viewers also liked

Viewers also liked (20)

React js
React jsReact js
React js
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
Reactjs
Reactjs Reactjs
Reactjs
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
React.js in real world apps.
React.js in real world apps. React.js in real world apps.
React.js in real world apps.
 
AngularJs
AngularJsAngularJs
AngularJs
 
React, ES6, and Meteor
React, ES6, and MeteorReact, ES6, and Meteor
React, ES6, and Meteor
 
React, Flux y React native
React, Flux y React nativeReact, Flux y React native
React, Flux y React native
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React – ¿Qué es React.js?
React – ¿Qué es React.js?React – ¿Qué es React.js?
React – ¿Qué es React.js?
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
 
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment WorkshopAtlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
Atlanta OpenStack 2014 Chef for OpenStack Deployment Workshop
 
OpenStack Deployment with Chef Workshop
OpenStack Deployment with Chef WorkshopOpenStack Deployment with Chef Workshop
OpenStack Deployment with Chef Workshop
 
Modern Web App Development using ClojureScript & React.js / Baishampayan “BG”...
Modern Web App Development using ClojureScript & React.js / Baishampayan “BG”...Modern Web App Development using ClojureScript & React.js / Baishampayan “BG”...
Modern Web App Development using ClojureScript & React.js / Baishampayan “BG”...
 
Event Driven Architecture - MeshU - Ilya Grigorik
Event Driven Architecture - MeshU - Ilya GrigorikEvent Driven Architecture - MeshU - Ilya Grigorik
Event Driven Architecture - MeshU - Ilya Grigorik
 
Introduction to Apache Synapse
Introduction to Apache SynapseIntroduction to Apache Synapse
Introduction to Apache Synapse
 
React Native
React NativeReact Native
React Native
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
 

Similar to An introduction to React.js

Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
vhazrati
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
jasonsich
 

Similar to An introduction to React.js (20)

Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
 
React/Redux
React/ReduxReact/Redux
React/Redux
 
ReactJS
ReactJSReactJS
ReactJS
 
React js
React jsReact js
React js
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
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
 
React outbox
React outboxReact outbox
React outbox
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
React - An Introduction
React - An IntroductionReact - An Introduction
React - An Introduction
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 

More from Emanuele DelBono

More from Emanuele DelBono (12)

The simplest thing that could possibly work
The simplest thing that could possibly workThe simplest thing that could possibly work
The simplest thing that could possibly work
 
Una crescita armoniosa
Una crescita armoniosaUna crescita armoniosa
Una crescita armoniosa
 
A sip of Elixir
A sip of ElixirA sip of Elixir
A sip of Elixir
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
 
Ruby seen by a C# developer
Ruby seen by a C# developerRuby seen by a C# developer
Ruby seen by a C# developer
 
Ruby loves DDD
Ruby loves DDDRuby loves DDD
Ruby loves DDD
 
An introduction to knockout.js
An introduction to knockout.jsAn introduction to knockout.js
An introduction to knockout.js
 
Node azure
Node azureNode azure
Node azure
 
Da programmatore a CEO
Da programmatore a CEODa programmatore a CEO
Da programmatore a CEO
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Test driving an MVVM App
Test driving an MVVM AppTest driving an MVVM App
Test driving an MVVM App
 
Mocking
MockingMocking
Mocking
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

An introduction to React.js