SlideShare a Scribd company logo
1 of 47
Lets Get Functional!
A Talk by Tyler Johnston @tylerjohnst
My Name is Tyler Johnston
What is React?
React is the functional view layer from Facebook designed
for building UIs with a focus on immutable data structures.
Who is using React?
Facebook, Instagram, AirBNB, Khan Academy,
WhatsApp, CodeAcademy
var HelloMessage = React.createClass({
render: function() {
return <div onClick={this.handleClick}>
Hello {this.props.name}
</div>;
},
handleClick: function(event) {
alert('Hello!');
}
});
React.render(<HelloMessage name="John" />,
document.body);
WTF?
That’s JSX and it’s completely optional.
style architectures with separate templates, co
Everything is a component.
React has no:
Models
Controllers
Templates
Directives
Just Components.
–Johnny Appleseed
“Type a quote here.”
Lets take a look at an example React interface.
ShoppingCartComponent
CartListComponent
CartProductComponent
Separate interface components and
not your technology.
Make your components:
Reusuable
Testable
Composable
Able to run in isolation
itecture is all about two-way binding and mult
React is about one-way data flow.
Components can create and communicate
with any child component.
var ParentComponent = React.createClass({
render: function() {
return <ChildComponent name="Mr. Smith"/>;
}
});
var ChildComponent = React.createClass({
render: function() {
return <div>{this.props.name}</div>;
}
});
Properties are immutable.
var ChildComponent = React.createClass({
...
doSomething: function() {
this.props.name = "Nope."
}
});
ver, state is mutable and can be used for prop
var ParentComponent = React.createClass({
handleSomething: function() {
this.setState({ active: true });
},
render: function() {
return <ChildComponent active={this.state.active} />;
}
});
var ChildComponent = React.createClass({
render: function() {
return <input type="checkbox" checked={this.props.active} />
}
});
Data flows one direction and your
application responds to changes in the
data.
Child components are not responsible for
maintaining any state. Their state passed
through the data properties from the
parent.
// Lets pretend `cart` is a model object of the cart.
var ShoppingCartComponent = React.createClass({
render: function() {
return <ShoppingCartListComponent cart={this.state.cart}
products={this.state.cart.products}/>
}
});
var ShoppingCartListComponent = React.createClass({
render: function() {
return this.props.products.map(function(product) {
return <ShoppingCartListProductComponent cart={this.props.cart}
product={product} />
}).bind(this);
}
});
var ShoppingCartListProductComponent = React.createClass({
render: function() {
return <input type="text" onChange={this.changeQuantity}>;
},
changeQuantity: function(event) {
this.props.cart.updateQuantityForProduct(
this.props.product,
event.target.value
);
}
});
With this style its data down and events up.
checking state and re-rendering but rather noti
But wouldn’t all of this re-rendering be
expensive? The DOM is so slow!
It would be in a traditional application
architecture. Templates must be re-
rendered as strings and reinserted in to the
DOM after it removed the previous content.
React solves this with its most well known
feature: The Virtual DOM.
Touching the DOM is evil.
sistent, it’s hard to test, it’s brittle and it’s extrem
React keeps an in memory representation
of the DOM structure of the components.
At render time React determines the least
amount of modifications required to update
the data to the current state.
Reacts complete control over its own DOM
allows it to do extremely optimized things.
The result is blazingly fast render times.
You can, however, access the DOM if you
need to.
var ShoppingCartComponent = React.createClass({
componentDidMount: function() {
var $el = $(this.getDOMNode());
this.setState({ width: $el.width() });
}
});
Now back to the Javascript
var HelloMessage = React.createClass({
render: function() {
return <div onClick={this.handleClick}>
Hello {this.props.name}
</div>;
},
handleClick: function(event) {
alert('Hello!');
}
});
React.render(<HelloMessage name="John" />,
document.body);
It’s just Javascript
var HelloMessage = React.createClass({displayName: "HelloMessage",
render: function() {
return React.createElement("div", {onClick: this.handleClick},
"Hello ", this.props.name
);
},
handleClick: function(event) {
alert('Hello!');
}
});
React.render(React.createElement(HelloMessage, {name: "John"}),
document.body);
echnology stack like a Handlebars when you c
You can compose multiple components in a
single render call.
var ShoppingCartComponent = React.createClass({
render: function() {
return <div>
<ShoppingCartTotal total={self.props.cart.total} />
<ShoppingCartList products={self.props.cart.products} />
<ShoppingCartDiscount discount={self.props.cart.discount} />
</div>;
}
});
One of the better features of React is the
relatively small surface area of the API.
This means it’s completely pluggable in to
whatever your current architecture is.
MyBackboneApp.Views.ProductList = Backbone.View.extend({
...
render: function() {
var component = React.render(
React.createElement(ShoppingCartComponent),
this.$('.cart-container').get(0)
)
this.cart.on('change', function(cart) {
component.setState({ cart: cart });
});
return this;
}
...
});
There are solutions for dealing with things
out side of the scope of the view and DOM.
After the release of React an architecture
pattern called Flux has emerged. It’s way
too big for this talk and I recommend you
check it out yourself.
Thanks!

More Related Content

What's hot

Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionVisual Engineering
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and ReduxMaxime Najim
 
Learning React - I
Learning React - ILearning React - I
Learning React - IMitch Chen
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from ScratchUdaya Kumar
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactDejan Glozic
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and ReduxGlib Kechyn
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Christian Lilley
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End祁源 朱
 
Going towards inversion of control and better design
Going towards inversion of control and better designGoing towards inversion of control and better design
Going towards inversion of control and better designoazabir
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to reactkiranabburi
 

What's hot (20)

Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
React & redux
React & reduxReact & redux
React & redux
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and Redux
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
React js basics
React js basicsReact js basics
React js basics
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from Scratch
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and React
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End
 
Going towards inversion of control and better design
Going towards inversion of control and better designGoing towards inversion of control and better design
Going towards inversion of control and better design
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
 

Similar to Get Functional with React Components

Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React TogetherSebastian Pederiva
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
A React Journey
A React JourneyA React Journey
A React JourneyLinkMe Srl
 
Vývojařská Plzeň - React
Vývojařská Plzeň - ReactVývojařská Plzeň - React
Vývojařská Plzeň - ReactViliam Elischer
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !Ritesh Kumar
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of Reactkristijanmkd
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJSLinkMe Srl
 
Techpaathshala ReactJS .pdf
Techpaathshala ReactJS .pdfTechpaathshala ReactJS .pdf
Techpaathshala ReactJS .pdfTechpaathshala
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfBOSC Tech Labs
 

Similar to Get Functional with React Components (20)

ReactJS
ReactJSReactJS
ReactJS
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
Intro to React.js
Intro to React.jsIntro to React.js
Intro to React.js
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
 
A React Journey
A React JourneyA React Journey
A React Journey
 
Vývojařská Plzeň - React
Vývojařská Plzeň - ReactVývojařská Plzeň - React
Vývojařská Plzeň - React
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
 
Techpaathshala ReactJS .pdf
Techpaathshala ReactJS .pdfTechpaathshala ReactJS .pdf
Techpaathshala ReactJS .pdf
 
react-en.pdf
react-en.pdfreact-en.pdf
react-en.pdf
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdf
 

Recently uploaded

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.pdfkalichargn70th171
 
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.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
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.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
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...kellynguyen01
 
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 CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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 WorkerThousandEyes
 
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 ...harshavardhanraghave
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

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
 
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
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
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
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
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...
 
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
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
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 ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

Get Functional with React Components

  • 1. Lets Get Functional! A Talk by Tyler Johnston @tylerjohnst
  • 2. My Name is Tyler Johnston
  • 3. What is React? React is the functional view layer from Facebook designed for building UIs with a focus on immutable data structures.
  • 4. Who is using React? Facebook, Instagram, AirBNB, Khan Academy, WhatsApp, CodeAcademy
  • 5. var HelloMessage = React.createClass({ render: function() { return <div onClick={this.handleClick}> Hello {this.props.name} </div>; }, handleClick: function(event) { alert('Hello!'); } }); React.render(<HelloMessage name="John" />, document.body); WTF?
  • 6. That’s JSX and it’s completely optional.
  • 7. style architectures with separate templates, co
  • 8. Everything is a component.
  • 11. Lets take a look at an example React interface.
  • 15. Separate interface components and not your technology. Make your components: Reusuable Testable Composable Able to run in isolation
  • 16. itecture is all about two-way binding and mult
  • 17. React is about one-way data flow. Components can create and communicate with any child component.
  • 18. var ParentComponent = React.createClass({ render: function() { return <ChildComponent name="Mr. Smith"/>; } }); var ChildComponent = React.createClass({ render: function() { return <div>{this.props.name}</div>; } });
  • 20. var ChildComponent = React.createClass({ ... doSomething: function() { this.props.name = "Nope." } });
  • 21. ver, state is mutable and can be used for prop
  • 22. var ParentComponent = React.createClass({ handleSomething: function() { this.setState({ active: true }); }, render: function() { return <ChildComponent active={this.state.active} />; } }); var ChildComponent = React.createClass({ render: function() { return <input type="checkbox" checked={this.props.active} /> } });
  • 23. Data flows one direction and your application responds to changes in the data. Child components are not responsible for maintaining any state. Their state passed through the data properties from the parent.
  • 24. // Lets pretend `cart` is a model object of the cart. var ShoppingCartComponent = React.createClass({ render: function() { return <ShoppingCartListComponent cart={this.state.cart} products={this.state.cart.products}/> } });
  • 25. var ShoppingCartListComponent = React.createClass({ render: function() { return this.props.products.map(function(product) { return <ShoppingCartListProductComponent cart={this.props.cart} product={product} /> }).bind(this); } });
  • 26. var ShoppingCartListProductComponent = React.createClass({ render: function() { return <input type="text" onChange={this.changeQuantity}>; }, changeQuantity: function(event) { this.props.cart.updateQuantityForProduct( this.props.product, event.target.value ); } });
  • 27. With this style its data down and events up. checking state and re-rendering but rather noti
  • 28. But wouldn’t all of this re-rendering be expensive? The DOM is so slow!
  • 29. It would be in a traditional application architecture. Templates must be re- rendered as strings and reinserted in to the DOM after it removed the previous content. React solves this with its most well known feature: The Virtual DOM.
  • 30. Touching the DOM is evil.
  • 31. sistent, it’s hard to test, it’s brittle and it’s extrem
  • 32. React keeps an in memory representation of the DOM structure of the components. At render time React determines the least amount of modifications required to update the data to the current state.
  • 33.
  • 34. Reacts complete control over its own DOM allows it to do extremely optimized things.
  • 35. The result is blazingly fast render times.
  • 36. You can, however, access the DOM if you need to. var ShoppingCartComponent = React.createClass({ componentDidMount: function() { var $el = $(this.getDOMNode()); this.setState({ width: $el.width() }); } });
  • 37. Now back to the Javascript
  • 38. var HelloMessage = React.createClass({ render: function() { return <div onClick={this.handleClick}> Hello {this.props.name} </div>; }, handleClick: function(event) { alert('Hello!'); } }); React.render(<HelloMessage name="John" />, document.body);
  • 40. var HelloMessage = React.createClass({displayName: "HelloMessage", render: function() { return React.createElement("div", {onClick: this.handleClick}, "Hello ", this.props.name ); }, handleClick: function(event) { alert('Hello!'); } }); React.render(React.createElement(HelloMessage, {name: "John"}), document.body);
  • 41. echnology stack like a Handlebars when you c
  • 42. You can compose multiple components in a single render call. var ShoppingCartComponent = React.createClass({ render: function() { return <div> <ShoppingCartTotal total={self.props.cart.total} /> <ShoppingCartList products={self.props.cart.products} /> <ShoppingCartDiscount discount={self.props.cart.discount} /> </div>; } });
  • 43. One of the better features of React is the relatively small surface area of the API.
  • 44. This means it’s completely pluggable in to whatever your current architecture is.
  • 45. MyBackboneApp.Views.ProductList = Backbone.View.extend({ ... render: function() { var component = React.render( React.createElement(ShoppingCartComponent), this.$('.cart-container').get(0) ) this.cart.on('change', function(cart) { component.setState({ cart: cart }); }); return this; } ... });
  • 46. There are solutions for dealing with things out side of the scope of the view and DOM. After the release of React an architecture pattern called Flux has emerged. It’s way too big for this talk and I recommend you check it out yourself.

Editor's Notes

  1. React is the functional view layer from Facebook designed for building UIs with a focus on immutable data structures.
  2. Facebook, Instagram, AirBNB, Khan Academy, WhatsApp, CodeAcademy
  3. How would we do this in a traditional MVC pattern? With jQuery spaghetti?
  4. Will reuse previously rendered elements and replace only the content that needs to be changed.