我正在查看DatePickerIOS组件的文档,他们使用getDefaultProps()来初始化组件中的道具。在React Native中使用ES6的getDefaultProps函数等效于什么?
getDefaultProps: function() {
return {
date: new Date(),
timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset()/60,
};
},
getInitialState: function() {
return {
date: this.props.date,
timeZoneOffsetInHours: this.props.timeZoneOffsetInHours,
};
},
什么是使用ES6语法的等价物?因为我一直在使用:
constructor(props) {
super(props);
this.state = {
//equivalent to getInitialState is here
};
}
我应该做这个.props = {}来设置我的默认道具吗?
如果有帮助,请标记为正确答案。 –