我正在查看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 = {}來設置我的默認道具嗎?
如果有幫助,請標記爲正確答案。 –