SlideShare a Scribd company logo
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/

More Related Content

PDF
Workshop React.js
PDF
Switch to React.js from AngularJS developer
PPTX
Rethinking Best Practices
PPTX
Better web apps with React and Redux
PPTX
React / Redux Architectures
PDF
React for Dummies
PPTX
React + Redux Introduction
PDF
Creating a WYSIWYG Editor with React
Workshop React.js
Switch to React.js from AngularJS developer
Rethinking Best Practices
Better web apps with React and Redux
React / Redux Architectures
React for Dummies
React + Redux Introduction
Creating a WYSIWYG Editor with React

What's hot (20)

PDF
React state managmenet with Redux
PDF
React, Redux, ES2015 by Max Petruck
PPTX
React, Flux and a little bit of Redux
PDF
React.js and Redux overview
PPTX
ProvJS: Six Months of ReactJS and Redux
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
React JS and Redux
PPTX
ReactJs presentation
PDF
Redux vs Alt
PDF
Intro to ReactJS
PPTX
PDF
Introduction to React & Redux
PPTX
React & redux
PDF
Modern Web Developement
PDF
Redux Universal
PDF
React Lifecycle and Reconciliation
PDF
Designing applications with Redux
PPTX
Better React state management with Redux
PDF
React native app with type script tutorial
React state managmenet with Redux
React, Redux, ES2015 by Max Petruck
React, Flux and a little bit of Redux
React.js and Redux overview
ProvJS: Six Months of ReactJS and Redux
Academy PRO: React JS. Redux & Tooling
React JS and Redux
ReactJs presentation
Redux vs Alt
Intro to ReactJS
Introduction to React & Redux
React & redux
Modern Web Developement
Redux Universal
React Lifecycle and Reconciliation
Designing applications with Redux
Better React state management with Redux
React native app with type script tutorial
Ad

Similar to React on es6+ (20)

PDF
Essentials and Impactful Features of ES6
PDF
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
PPTX
ReactJS.pptx
PDF
Es.next
PDF
ReactJS for Programmers
PDF
The Human Linter
PDF
The Human Linter — Ilya Gelman
PPTX
ReactJS for Beginners
PPTX
React.js - The Dawn of Virtual DOM
PPTX
React & Redux JS
PDF
2018 05-16 Evolving Technologies: React, Babel & Webpack
PPTX
ES6: Features + Rails
PDF
JavaScript ES6
PDF
Introductionandgreetings
PPTX
User Interface
PDF
ESCMAScript 6: Get Ready For The Future. Now
PDF
ES6 - Level up your JavaScript Skills
PDF
ES6 General Introduction
PDF
ECMAScript 6
PDF
Introduction of ES2015
Essentials and Impactful Features of ES6
React ES5 to ES6 | React ES5 vs ES6 | React Tutorial for Beginners | React on...
ReactJS.pptx
Es.next
ReactJS for Programmers
The Human Linter
The Human Linter — Ilya Gelman
ReactJS for Beginners
React.js - The Dawn of Virtual DOM
React & Redux JS
2018 05-16 Evolving Technologies: React, Babel & Webpack
ES6: Features + Rails
JavaScript ES6
Introductionandgreetings
User Interface
ESCMAScript 6: Get Ready For The Future. Now
ES6 - Level up your JavaScript Skills
ES6 General Introduction
ECMAScript 6
Introduction of ES2015
Ad

More from Nikolaus Graf (8)

PDF
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
PDF
Reason and GraphQL
PDF
Get started with Reason
PDF
Introduction to Serverless
PDF
Serverless Framework Intro
PDF
Rich text editing with Draft.js
PDF
AngularDart Introduction
PDF
Web Components
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Reason and GraphQL
Get started with Reason
Introduction to Serverless
Serverless Framework Intro
Rich text editing with Draft.js
AngularDart Introduction
Web Components

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
A Presentation on Artificial Intelligence
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
A Presentation on Artificial Intelligence
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Monthly Chronicles - July 2025
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity

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/