- require 与 import -> es6 不再使用require,使用import
// es5
var React = require('react');
// es6
import React form 'react'
- export 与 exports
// es5
modal.exports = Component;
// es6
export default Component;
- component 和 function
// es5
var MyComponent = React.createClass({
return function() {
return <>hello</>
}
})
// es6
class MyComponent extends React.Component {
render() {
return <>hello</>;
}
}
- props
es5: propsTypes
es6: this.props
- state
// es5
var Counter = createReactClass({
getInitialState: function() {
return {count: this.props.initialCount};
},
});
// es6
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
}