SlideShare a Scribd company logo
R E A C T. J S
by Stefano Ceschi Berrini @stecb
Rethinking UI Development
Programmers in Padua - March 18th, 2015
I’m a Software Engineer @ Timerepublik.
I’m not a React expert. I’m still learning it,
I’m hacking/experimenting with it and I’m really LOVING IT.
So, let’s share this learning process.
http://stecb.ninja
Reactjs: Rethinking UI Devel
It’s a JavaScript library for the the UI built by
VM C
it automa(g|t)ically keeps the interface up-to-date when data changes
+
As of March, 18th 2015
Instagram
Facebook
• AirBnB
• Atlassian
• BBC
• Imgur
• Khan Academy
• Pivotal Tracker
• Reddit
• Whatsapp
• Wired
• Yahoo
• …
Keys
• Components (+ JSX)
• Virtual DOM
• One-way data binding
key #1: Components
Everything in React is a modular/reusable
component:
• react HTML elements
• Custom react components
• Collections/composition of the above
Think about a component as a state-machine. Don’t think about the DOM.
key #1: Components
A component is a React class. It can take
input data, it can have a state and you can:
• define methods
• render a tree of functions
When you add a component to your UI, you’re just invoking a function.
mandatory
key #1: Components
key #1: Components
JSX
JS
optional
var HelloWorld = React.createClass({
render: function() {
return <div>Hello world, {this.props.name}!</div>;
}
});
React.render(<HelloWorld name="Bruce" />, document.getElementById('main'));
var HelloWorld = React.createClass({
render: function() {
return React.createElement("div", null, "Hello world, ", this.props.name, "!");
}
});
React.render(React.createElement(HelloWorld, {name: "Bruce"}),
document.getElementById('main'));
?harmony for ES6
key #1: Components JSX
JS syntactic sugar: a concise and familiar syntax for
defining tree structures with attributes.
XML like elements => function + args
key #1: Components properties
Props are the options/configuration of a
component, they are data passed from
parents to children and they are
immmutable.
If you think a property of a component could changed over time, then that should be part of its state.
key #1: Components properties
var Box = React.createClass({
render: function() {
var list = this.props.list.map(function(item) {
return <li>{item}</li>
});
return (
<div>
<h1>{this.props.title}</h1>
<ul>
{list}
</ul>
</div>
);
}
});
React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
key #1: Components state
State is mutable and should contain data
that a component's event handlers may
change to trigger a UI update (i.e. User
interactions, Server responses etc)
State is optional and you should avoid it as much as possible, to reduce complexity!
setState(data, callback)
key #1: Components state
var Box = React.createClass({
getInitialState: function() {
return {
hasDetailsVisible: false
};
},
handleToggle: function() {
this.setState({
hasDetailsVisible: !this.state.hasDetailsVisible
});
},
render: function() {
var list = this.props.list.map(function(item) {
return <li>{item}</li>
});
var detailsStyle = this.state.hasDetailsVisible ? {display: 'block'} : {display: 'none'};
return (
<div>
<h1>{this.props.title}</h1>
<button onClick={this.handleToggle}>toggle details</button>
<ul style={detailsStyle}>
{list}
</ul>
</div>
);
}
});
React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
key #1: Components events
Just three words
Forget about jQuery
key #1: Components events
http://facebook.github.io/react/docs/events.html
Synthetic events. They work identically on every browser
Clipboard, Keyboard, Focus, Form,
Mouse, Touch, UI, Wheel
key #1: Components events
var Box = React.createClass({
getInitialState: function() {
return {
hasDetailsVisible: false
};
},
handleToggle: function(event) {
this.setState({
hasDetailsVisible: !this.state.hasDetailsVisible
});
},
render: function() {
var list = this.props.list.map(function(item) {
return <li>{item}</li>
});
var detailsStyle = this.state.hasDetailsVisible ? {display: 'block'} : {display: 'none'};
return (
<div>
<h1>{this.props.title}</h1>
<button onClick={this.handleToggle}>toggle details</button>
<ul style={detailsStyle}>
{list}
</ul>
</div>
);
}
});
React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
key #1: Components DOM elements
var Input = React.createClass({
handleChange: function(event) {
console.log(event.target.value);
},
componentDidMount: function() {
React.findDOMNode(this.refs.myInput).focus();
},
render: function() {
return (
<input type="text" ref="myInput" onChange={this.handleChange} />
);
}
});
http://facebook.github.io/react/docs/component-specs.html
React internally uses a virtual representation of the
DOM
It mutates the real DOM by using a tree diff algorithm +
heuristic O(n^3) => O(n)
You can think about re-rendering your entire application
on every update without worrying about performance!
key #2: Virtual DOM
https://www.flickr.com/photos/usnavy/5815022252
Why is it so fast?
JS execution is FAST, real DOM mutations are SLOW
So, being able to re-render the entire application by mutating
JUST what changed on the UI is the most important thing
key #2: Virtual DOM
State N State N+1
Changed attributes, just update them on the real DOM
The NodeType has changed, throw away that node (+subtree) and replace
it with a new node!
key #2: Virtual DOM
key #3: One-way Data Binding
<ComponentA />
<ComponentB /> <ComponentD />
<ComponentC />
Data (props) flows only in one way. From the Owner to child.
Example
Not just the UI…
Architecture: Flux
React on the server: React.renderToString(component)
drumroll… React Native
Useful resources
Official React website
https://github.com/enaqx/awesome-react
React VS ember/angular/backbone
React.js Conf 2015 videos
Starter kit for Isomorphic webapps with React and Flux
Thanks
Q&A

More Related Content

Similar to Reactjs: Rethinking UI Devel (20)

PDF
Workshop 19: ReactJS Introduction
Visual Engineering
 
PDF
React for Dummies
Mitch Chen
 
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
PPTX
Introduction to React JS.pptx
SHAIKIRFAN715544
 
PPTX
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
PPTX
ReactJS Code Impact
Raymond McDermott
 
PDF
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
PDF
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
PPTX
Learn react.js with me!
Shivani Thakur Daxini
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Tech Talk on ReactJS
Atlogys Technical Consulting
 
PDF
React js
Rajesh Kolla
 
PDF
Stay with React.js in 2020
Jerry Liao
 
PPTX
React - Start learning today
Nitin Tyagi
 
PPTX
Intro to React.js
Smita Prasad
 
PDF
ReactJS - A quick introduction to Awesomeness
Ronny Haase
 
PPTX
ReactJS (1)
George Tony
 
PPTX
React js - The Core Concepts
Divyang Bhambhani
 
PDF
Welcome to React & Flux !
Ritesh Kumar
 
PPTX
ReactJs presentation
nishasowdri
 
Workshop 19: ReactJS Introduction
Visual Engineering
 
React for Dummies
Mitch Chen
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
Introduction to React JS.pptx
SHAIKIRFAN715544
 
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
ReactJS Code Impact
Raymond McDermott
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
Learn react.js with me!
Shivani Thakur Daxini
 
ReactJS presentation
Thanh Tuong
 
Tech Talk on ReactJS
Atlogys Technical Consulting
 
React js
Rajesh Kolla
 
Stay with React.js in 2020
Jerry Liao
 
React - Start learning today
Nitin Tyagi
 
Intro to React.js
Smita Prasad
 
ReactJS - A quick introduction to Awesomeness
Ronny Haase
 
ReactJS (1)
George Tony
 
React js - The Core Concepts
Divyang Bhambhani
 
Welcome to React & Flux !
Ritesh Kumar
 
ReactJs presentation
nishasowdri
 

Recently uploaded (20)

PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Ad

Reactjs: Rethinking UI Devel

  • 1. R E A C T. J S by Stefano Ceschi Berrini @stecb Rethinking UI Development Programmers in Padua - March 18th, 2015
  • 2. I’m a Software Engineer @ Timerepublik. I’m not a React expert. I’m still learning it, I’m hacking/experimenting with it and I’m really LOVING IT. So, let’s share this learning process. http://stecb.ninja
  • 4. It’s a JavaScript library for the the UI built by VM C it automa(g|t)ically keeps the interface up-to-date when data changes + As of March, 18th 2015
  • 7. • AirBnB • Atlassian • BBC • Imgur • Khan Academy • Pivotal Tracker • Reddit • Whatsapp • Wired • Yahoo • …
  • 8. Keys • Components (+ JSX) • Virtual DOM • One-way data binding
  • 9. key #1: Components Everything in React is a modular/reusable component: • react HTML elements • Custom react components • Collections/composition of the above Think about a component as a state-machine. Don’t think about the DOM.
  • 10. key #1: Components A component is a React class. It can take input data, it can have a state and you can: • define methods • render a tree of functions When you add a component to your UI, you’re just invoking a function. mandatory
  • 12. key #1: Components JSX JS optional var HelloWorld = React.createClass({ render: function() { return <div>Hello world, {this.props.name}!</div>; } }); React.render(<HelloWorld name="Bruce" />, document.getElementById('main')); var HelloWorld = React.createClass({ render: function() { return React.createElement("div", null, "Hello world, ", this.props.name, "!"); } }); React.render(React.createElement(HelloWorld, {name: "Bruce"}), document.getElementById('main')); ?harmony for ES6
  • 13. key #1: Components JSX JS syntactic sugar: a concise and familiar syntax for defining tree structures with attributes. XML like elements => function + args
  • 14. key #1: Components properties Props are the options/configuration of a component, they are data passed from parents to children and they are immmutable. If you think a property of a component could changed over time, then that should be part of its state.
  • 15. key #1: Components properties var Box = React.createClass({ render: function() { var list = this.props.list.map(function(item) { return <li>{item}</li> }); return ( <div> <h1>{this.props.title}</h1> <ul> {list} </ul> </div> ); } }); React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
  • 16. key #1: Components state State is mutable and should contain data that a component's event handlers may change to trigger a UI update (i.e. User interactions, Server responses etc) State is optional and you should avoid it as much as possible, to reduce complexity! setState(data, callback)
  • 17. key #1: Components state var Box = React.createClass({ getInitialState: function() { return { hasDetailsVisible: false }; }, handleToggle: function() { this.setState({ hasDetailsVisible: !this.state.hasDetailsVisible }); }, render: function() { var list = this.props.list.map(function(item) { return <li>{item}</li> }); var detailsStyle = this.state.hasDetailsVisible ? {display: 'block'} : {display: 'none'}; return ( <div> <h1>{this.props.title}</h1> <button onClick={this.handleToggle}>toggle details</button> <ul style={detailsStyle}> {list} </ul> </div> ); } }); React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
  • 18. key #1: Components events Just three words Forget about jQuery
  • 19. key #1: Components events http://facebook.github.io/react/docs/events.html Synthetic events. They work identically on every browser Clipboard, Keyboard, Focus, Form, Mouse, Touch, UI, Wheel
  • 20. key #1: Components events var Box = React.createClass({ getInitialState: function() { return { hasDetailsVisible: false }; }, handleToggle: function(event) { this.setState({ hasDetailsVisible: !this.state.hasDetailsVisible }); }, render: function() { var list = this.props.list.map(function(item) { return <li>{item}</li> }); var detailsStyle = this.state.hasDetailsVisible ? {display: 'block'} : {display: 'none'}; return ( <div> <h1>{this.props.title}</h1> <button onClick={this.handleToggle}>toggle details</button> <ul style={detailsStyle}> {list} </ul> </div> ); } }); React.render(<Box title="Cool Box" list={['item 1', 'item 2', 'item 3', 'item N']} />, document.body);
  • 21. key #1: Components DOM elements var Input = React.createClass({ handleChange: function(event) { console.log(event.target.value); }, componentDidMount: function() { React.findDOMNode(this.refs.myInput).focus(); }, render: function() { return ( <input type="text" ref="myInput" onChange={this.handleChange} /> ); } }); http://facebook.github.io/react/docs/component-specs.html
  • 22. React internally uses a virtual representation of the DOM It mutates the real DOM by using a tree diff algorithm + heuristic O(n^3) => O(n) You can think about re-rendering your entire application on every update without worrying about performance! key #2: Virtual DOM
  • 23. https://www.flickr.com/photos/usnavy/5815022252 Why is it so fast? JS execution is FAST, real DOM mutations are SLOW So, being able to re-render the entire application by mutating JUST what changed on the UI is the most important thing key #2: Virtual DOM
  • 24. State N State N+1 Changed attributes, just update them on the real DOM The NodeType has changed, throw away that node (+subtree) and replace it with a new node! key #2: Virtual DOM
  • 25. key #3: One-way Data Binding <ComponentA /> <ComponentB /> <ComponentD /> <ComponentC /> Data (props) flows only in one way. From the Owner to child.
  • 27. Not just the UI… Architecture: Flux React on the server: React.renderToString(component) drumroll… React Native
  • 28. Useful resources Official React website https://github.com/enaqx/awesome-react React VS ember/angular/backbone React.js Conf 2015 videos Starter kit for Isomorphic webapps with React and Flux