【发布时间】:2018-03-01 00:01:18
【问题描述】:
我正在尝试迁移到 recompose,但我有点困惑:
我通常在 render() 方法的开头写一些代码,例如检查值,设置样式,...
如果我使用recompose,我在哪里可以写这些代码?
例如这个:
render() {
const { classes } = this.props;
var startPos;
if (this.props.isGeolocationAvailable && this.props.isGeolocationEnabled && this.props.coords != undefined) {
console.log("location : " + this.props.coords.longitude + ":" + this.props.coords.latitude)
this.state.initial_location = this.props.coords;
}
else {
this.state.initial_location = { longitude: 0, latitude: 0 };
}
...
【问题讨论】:
-
这不是你应该设置状态的方式。你甚至不应该在
render中设置状态,它是零意义的。
标签: node.js reactjs react-redux recompose