SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
React on ES6+
React on ES6+ @nikgraf
Nik Graf
@nikgraf

nik@nikgraf.com
Creator of Belle
Working with StarterSquad
React on ES6+ @nikgraf
ECMAScript 5
December 2009 - ECMAScript 5 was published
React on ES6+ @nikgraf
Why bother about ES6+?
Classes

Enhanced Object Literals

Block-scoped binding constructs (let + const)

Property Initialisers

Arrow Functions

Template Strings

Spread Attributes

Deconstructing Attributes

Generators

DataStructures (Map, Set, WeakMap, WeakSet)

… and many more
React on ES6+ @nikgraf
ES6 is finalised


Final Draft April 14, 2015 Rev 38

http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#final_draft



🎉🎂 🎈🎊
React on ES6+ @nikgraf
People use ES6+
React on ES6+ @nikgraf
ECMAScript 6
April 2015 - ECMAScript 2015 (ES6) finalised
React on ES6+ @nikgraf
Compilers
Traceur
JSTransform (deprecated)
Babel
React on ES6+ @nikgraf


Created by Sebastian McKenzie (started fall 2014)


- JSX Support, ES6 Support, ES7 Support

- Widely adopted
React on ES6+ @nikgraf
Facebook ❤ Babel
React on ES6+ @nikgraf
Block-scoped binding constructs
const hello = 'Hello';
hello = 'Hola'; // this is not valid
React on ES6+ @nikgraf
Block-scoped binding constructs
function varTest() {
var x = 31;
if (true) {
var x = 71; // same variable!
console.log(x); // 71
}
console.log(x); // 71
}
React on ES6+ @nikgraf
Block-scoped binding constructs
function letTest() {
let x = 31;
if (true) {
let x = 71; // different variable
console.log(x); // 71
}
console.log(x); // 31
}
React on ES6+ @nikgraf
Classes
// The ES5 way
var Photo = React.createClass({
handleDoubleTap: function(e) { … },
render: function() { … },
});
// The ES6+ way
class Photo extends React.Component {
handleDoubleTap(e) { … }
render() { … }
}
React on ES6+ @nikgraf
Classes
// The ES5 way
var EmbedModal = React.createClass({
componentWillMount: function() { … },
});
// The ES6+ way
class EmbedModal extends React.Component {
constructor(props) {
super(props);
}
}
React on ES6+ @nikgraf
Property Initialisers
// The ES5 way
var Video = React.createClass({
getDefaultProps: function() {
return {
autoPlay: false,
maxLoops: 10,
};
},
getInitialState: function() {
return {
loopsRemaining: this.props.maxLoops,
};
},
propTypes: {
autoPlay: React.PropTypes.bool.isRequired,
maxLoops: React.PropTypes.number.isRequired
},
});
React on ES6+ @nikgraf
Property Initialisers
// The ES6+ way
class Video extends React.Component {
static defaultProps = {
autoPlay: false,
maxLoops: 10,
}
static propTypes = {
autoPlay: React.PropTypes.bool.isRequired,
maxLoops: React.PropTypes.number.isRequired
}
state = {
loopsRemaining: this.props.maxLoops,
}
}
React on ES6+ @nikgraf
Arrow Functions
// ES5
[2,2,3].map(function(item) {
return item + 1;
});
// Expression bodies
[2,2,3].map(item => item + 1);
// [3,3,4]
[2,2,3].map((item, index) => item + index);
// [2,3,5]
// Statement bodies
[2,2,3].forEach(item => {
if (item === 2) {
console.log('Found the number 2');
}
});
React on ES6+ @nikgraf
Arrow Functions
// Lexical this
const bob = {
_name: "Bob",
_friends: [],
printFriends() {
this._friends.forEach(friend =>
console.log(this._name + " knows " + friend));
}
}
React on ES6+ @nikgraf
Template Strings
// Multiline strings
const text = `In ES5 this is
not legal.
Good to know.`;
// Interpolate variable bindings
const city = 'Vienna';
const time = 'today';
// ES5
console.log('Hello ' + city + ', how are you ' + time + '?');
// ES6+
console.log(`Hello ${city}, how are you ${time}?`);
// results in "Hello Vienna, how are you today?"
React on ES6+ @nikgraf
Spread Attributes
const photoSet = {
coverIndex: 1,
photos: [
{ url: '…' },
{ url: '…' }
]
}
// explicit assignment
<PhotoGrid coverIndex={ photoSet.coverIndex }
photos={ photoSet.photos } />
// spread attributes
<PhotoGrid { ...photoSet } />
React on ES6+ @nikgraf
Deconstructing
var x = [1,2,3];
// ES5
var a = x[0];
var b = x[2];
// ES6+ list matching
const [a, , b] = x;
React on ES6+ @nikgraf
Deconstructing
this.props = {
className: 'photo box',
isSquare: true,
width: 200
}
const { className, ...others } = this.props;
// others contains all properties of this.props
// except for className
// className == 'photo box'
// others == { isSquare: true, width: 200 }
React on ES6+ @nikgraf
Deconstruct & Spread
class PhotoPage extends React.Component {
onLoadMore() { … }
render() {
const {
className,
...otherProps
} = this.props;
return (
<div className={className}>
<PhotoGrid {...otherProps} />
<button onClick={ this.onLoadMore.bind(this) }>
Load more
</button>
</div>
);
}
}
React on ES6+ @nikgraf
ProTip: Eslint
created by Nicholas Zakas
- Enable/Disabled Rules on demand
- Follows the standard + JSX Support
- AirBnB’s fantastic JavaScript Guide + .eslintrc

https://github.com/airbnb/javascript/
React on ES6+ @nikgraf
Eslint as Atom Plugin
React on ES6+ @nikgraf
End
Special thanks to Steven Luscher for the original post
on “React on ES6+”

https://babeljs.io/blog/2015/06/07/react-on-es6-plus
Checkout Belle

https://nikgraf.github.io/belle/

Contenu connexe

Tendances

Tendances (20)

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, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
ProvJS: Six Months of ReactJS and Redux
ProvJS:  Six Months of ReactJS and ReduxProvJS:  Six Months of ReactJS and Redux
ProvJS: Six Months of ReactJS and Redux
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
React js
React jsReact js
React js
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & Redux
 
React & redux
React & reduxReact & redux
React & redux
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developement
 
Redux Universal
Redux UniversalRedux Universal
Redux Universal
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
React Lifecycle and Reconciliation
React Lifecycle and ReconciliationReact Lifecycle and Reconciliation
React Lifecycle and Reconciliation
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with Redux
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 

Similaire à React on es6+

EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Gaurav Behere
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptMohd Saeed
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)Domenic Denicola
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowKrzysztof Szafranek
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Applitools
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesRay Toal
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8Rafael Casuso Romate
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...Sencha
 

Similaire à React on es6+ (20)

ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
"let ECMAScript = 6"
"let ECMAScript = 6" "let ECMAScript = 6"
"let ECMAScript = 6"
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. Now
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
 

Plus de Nikolaus Graf

Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & ReasonType Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & ReasonNikolaus Graf
 
Get started with Reason
Get started with ReasonGet started with Reason
Get started with ReasonNikolaus Graf
 
Introduction to Serverless
Introduction to ServerlessIntroduction to Serverless
Introduction to ServerlessNikolaus Graf
 
Serverless Framework Intro
Serverless Framework IntroServerless Framework Intro
Serverless Framework IntroNikolaus Graf
 
Rich text editing with Draft.js
Rich text editing with Draft.jsRich text editing with Draft.js
Rich text editing with Draft.jsNikolaus Graf
 
AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart IntroductionNikolaus Graf
 

Plus de Nikolaus Graf (8)

Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & ReasonType Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
 
Reason and GraphQL
Reason and GraphQLReason and GraphQL
Reason and GraphQL
 
Get started with Reason
Get started with ReasonGet started with Reason
Get started with Reason
 
Introduction to Serverless
Introduction to ServerlessIntroduction to Serverless
Introduction to Serverless
 
Serverless Framework Intro
Serverless Framework IntroServerless Framework Intro
Serverless Framework Intro
 
Rich text editing with Draft.js
Rich text editing with Draft.jsRich text editing with Draft.js
Rich text editing with Draft.js
 
AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart Introduction
 
Web Components
Web ComponentsWeb Components
Web Components
 

Dernier

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

React on es6+

  • 2. React on ES6+ @nikgraf Nik Graf @nikgraf
 nik@nikgraf.com Creator of Belle Working with StarterSquad
  • 3. React on ES6+ @nikgraf ECMAScript 5 December 2009 - ECMAScript 5 was published
  • 4. React on ES6+ @nikgraf Why bother about ES6+? Classes
 Enhanced Object Literals
 Block-scoped binding constructs (let + const)
 Property Initialisers
 Arrow Functions
 Template Strings
 Spread Attributes
 Deconstructing Attributes
 Generators
 DataStructures (Map, Set, WeakMap, WeakSet)
 … and many more
  • 5. React on ES6+ @nikgraf ES6 is finalised 
 Final Draft April 14, 2015 Rev 38
 http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#final_draft
 
 🎉🎂 🎈🎊
  • 6. React on ES6+ @nikgraf People use ES6+
  • 7. React on ES6+ @nikgraf ECMAScript 6 April 2015 - ECMAScript 2015 (ES6) finalised
  • 8. React on ES6+ @nikgraf Compilers Traceur JSTransform (deprecated) Babel
  • 9. React on ES6+ @nikgraf 
 Created by Sebastian McKenzie (started fall 2014) 
 - JSX Support, ES6 Support, ES7 Support
 - Widely adopted
  • 10. React on ES6+ @nikgraf Facebook ❤ Babel
  • 11. React on ES6+ @nikgraf Block-scoped binding constructs const hello = 'Hello'; hello = 'Hola'; // this is not valid
  • 12. React on ES6+ @nikgraf Block-scoped binding constructs function varTest() { var x = 31; if (true) { var x = 71; // same variable! console.log(x); // 71 } console.log(x); // 71 }
  • 13. React on ES6+ @nikgraf Block-scoped binding constructs function letTest() { let x = 31; if (true) { let x = 71; // different variable console.log(x); // 71 } console.log(x); // 31 }
  • 14. React on ES6+ @nikgraf Classes // The ES5 way var Photo = React.createClass({ handleDoubleTap: function(e) { … }, render: function() { … }, }); // The ES6+ way class Photo extends React.Component { handleDoubleTap(e) { … } render() { … } }
  • 15. React on ES6+ @nikgraf Classes // The ES5 way var EmbedModal = React.createClass({ componentWillMount: function() { … }, }); // The ES6+ way class EmbedModal extends React.Component { constructor(props) { super(props); } }
  • 16. React on ES6+ @nikgraf Property Initialisers // The ES5 way var Video = React.createClass({ getDefaultProps: function() { return { autoPlay: false, maxLoops: 10, }; }, getInitialState: function() { return { loopsRemaining: this.props.maxLoops, }; }, propTypes: { autoPlay: React.PropTypes.bool.isRequired, maxLoops: React.PropTypes.number.isRequired }, });
  • 17. React on ES6+ @nikgraf Property Initialisers // The ES6+ way class Video extends React.Component { static defaultProps = { autoPlay: false, maxLoops: 10, } static propTypes = { autoPlay: React.PropTypes.bool.isRequired, maxLoops: React.PropTypes.number.isRequired } state = { loopsRemaining: this.props.maxLoops, } }
  • 18. React on ES6+ @nikgraf Arrow Functions // ES5 [2,2,3].map(function(item) { return item + 1; }); // Expression bodies [2,2,3].map(item => item + 1); // [3,3,4] [2,2,3].map((item, index) => item + index); // [2,3,5] // Statement bodies [2,2,3].forEach(item => { if (item === 2) { console.log('Found the number 2'); } });
  • 19. React on ES6+ @nikgraf Arrow Functions // Lexical this const bob = { _name: "Bob", _friends: [], printFriends() { this._friends.forEach(friend => console.log(this._name + " knows " + friend)); } }
  • 20. React on ES6+ @nikgraf Template Strings // Multiline strings const text = `In ES5 this is not legal. Good to know.`; // Interpolate variable bindings const city = 'Vienna'; const time = 'today'; // ES5 console.log('Hello ' + city + ', how are you ' + time + '?'); // ES6+ console.log(`Hello ${city}, how are you ${time}?`); // results in "Hello Vienna, how are you today?"
  • 21. React on ES6+ @nikgraf Spread Attributes const photoSet = { coverIndex: 1, photos: [ { url: '…' }, { url: '…' } ] } // explicit assignment <PhotoGrid coverIndex={ photoSet.coverIndex } photos={ photoSet.photos } /> // spread attributes <PhotoGrid { ...photoSet } />
  • 22. React on ES6+ @nikgraf Deconstructing var x = [1,2,3]; // ES5 var a = x[0]; var b = x[2]; // ES6+ list matching const [a, , b] = x;
  • 23. React on ES6+ @nikgraf Deconstructing this.props = { className: 'photo box', isSquare: true, width: 200 } const { className, ...others } = this.props; // others contains all properties of this.props // except for className // className == 'photo box' // others == { isSquare: true, width: 200 }
  • 24. React on ES6+ @nikgraf Deconstruct & Spread class PhotoPage extends React.Component { onLoadMore() { … } render() { const { className, ...otherProps } = this.props; return ( <div className={className}> <PhotoGrid {...otherProps} /> <button onClick={ this.onLoadMore.bind(this) }> Load more </button> </div> ); } }
  • 25. React on ES6+ @nikgraf ProTip: Eslint created by Nicholas Zakas - Enable/Disabled Rules on demand - Follows the standard + JSX Support - AirBnB’s fantastic JavaScript Guide + .eslintrc
 https://github.com/airbnb/javascript/
  • 26. React on ES6+ @nikgraf Eslint as Atom Plugin
  • 27. React on ES6+ @nikgraf End Special thanks to Steven Luscher for the original post on “React on ES6+”
 https://babeljs.io/blog/2015/06/07/react-on-es6-plus Checkout Belle
 https://nikgraf.github.io/belle/