
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
React-ES5-To-ES6-Checklist
Advanced tools
ECMAScript2015(ES6) is the latest version of the ECMAScript standard.
React is a declarative, efficient, and flexible JavaScript library for building user interfaces.
In the earlier days of React development, many programms were written in ES5. Howerver, as ES6 is more widely accepted now and with the help of transplier tools like Babel, we can gradually retire some ES5 code and adopt some ES6 new features in React development.
Here is a check list to help you translate your ES5 code to newer version in React. You are welcome to contribute with more items provided below.
ES5
//ES5
var React = require("react");
var PropTypes = React.PropTypes;
ES6
import React, { Component, PropTypes } from 'react';
ES5
var Mycomponent = React.createClass({
render: function() {
return (
<div>ES5</div>
);
},
});
ES6
class Mycomponent extends React.Component {
render() {
return (
<div>ES6</div>
);
}
}
ES5
var Mycomponent = React.createClass({
render: function() {
return (
<div>ES5</div>
);
},
});
module.exports = Mycomponent;
ES6
export default class Mycomponent extends React.Component {
render() {
return (
<div>ES6</div>
);
}
}
ES5
var Mycomponent = React.createClass({
componentWillMount: function(){
},
render: function() {
return (
<div>ES5</div>
);
},
});
module.exports = Mycomponent;
ES6
export default class Mycomponent extends React.Component {
componentWillMount() {
}
render() {
return (
<div>ES6</div>
);
}
}
ES5
var Video = React.createClass({
getDefaultProps: function() {
return {
autoPlay: false,
maxLoops: 10,
};
},
propTypes: {
autoPlay: React.PropTypes.bool.isRequired,
maxLoops: React.PropTypes.number.isRequired,
posterFrameSrc: React.PropTypes.string.isRequired,
videoSrc: React.PropTypes.string.isRequired,
},
render: function() {
return (
<View />
);
},
});
ES6
class Video extends React.Component {
render() {
return (
<View />
);
}
}
Video.defaultProps = {
autoPlay: false,
maxLoops: 10,
};
Video.propTypes = {
autoPlay: React.PropTypes.bool.isRequired,
maxLoops: React.PropTypes.number.isRequired,
posterFrameSrc: React.PropTypes.string.isRequired,
videoSrc: React.PropTypes.string.isRequired,
};
ES7:
class Video extends React.Component {
static defaultProps = {
autoPlay: false,
maxLoops: 10,
}
static propTypes = {
autoPlay: React.PropTypes.bool.isRequired,
maxLoops: React.PropTypes.number.isRequired,
posterFrameSrc: React.PropTypes.string.isRequired,
videoSrc: React.PropTypes.string.isRequired,
}
state = {
loopsRemaining: this.props.maxLoops,
}
}
ES5
var Header = React.createClass({
getInitialState: function() {
return {
title: this.props.title
};
},
});
ES6
export default class Header extends Component {
constructor(props) {
super(props);
this.state = {
title: props.title
};
}
}
ES7
export default class Header extends Component {
state = {
title: this.props.title
};
// followed by constructor...
}
class AutoloadingPostsGrid extends React.Component {
render() {
var {
className,
...others, // contains all properties of this.props except for className
} = this.props;
return (
<div className={className}>
<PostsGrid {...others} />
<button onClick={this.handleLoadMoreClick}>Load more</button>
</div>
);
}
}
MIT
FAQs
The missing manual of upgrading ES5 React project to ES6+
We found that React-ES5-To-ES6-Checklist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.