【发布时间】:2016-06-18 15:17:49
【问题描述】:
两者相比有什么优势?
一个被弃用了,我应该使用更新的那个吗?
我应该创建组件还是 React 类来开发我的 UI?
我看到了一些使用组件的例子。例如:
export default class ItemList extends Component {
constructor(props) {
//binding functions
this.renderHeader = this.renderHeader.bind(this);
this.renderRow = this.renderRow.bind(this);
super(props);
this.state = {
dataSource: this.props.state.planDataSource,
planName: null
}
}
和其他人使用
var ItemList = React.createClass({
getInitialState: function() {
return {
dataSource: this.props.state.planDataSource,
planName: null
};
},
我正在通过示例学习 react-native,但我不知道哪个是首选。
我最近将一个 React 类转换为一个组件,发现“this”指针不起作用,因为 React 类使用了自动绑定,而组件需要显式绑定。
【问题讨论】:
标签: class components react-native