模塊引用
ES5 | ES6 |
---|---|
var React = require("react"); |
import React from 'react'; |
組件化
ES5 | ES6 |
---|---|
var ComponentName = React.createClass({}); module.exports = ComponentName; |
export default class ComponentName extends Component {}; |
組件方法
ES5 | ES6 |
---|---|
componentWillMount: function(){},//有逗號 |
compoentWillMount(){}//沒有逗號 |
屬性類型和默認屬性
ES5 | ES6 |
---|---|
getDefaultProps: function(){return {};}, propTypes: {name: React.PropTypes.bool.isRequired},// 有逗號 |
static defaultProps={}; static propTypes={};// 有分號 |
state
ES5 | ES6 |
---|---|
getInitialState:function(){return{};}, |
state={};//第一種 constructor(props){super(props);this.state={};}//第二種 |