我在构造函数this.state = {};
中设置了状态,但prevState
方法中的calculateState
参数为null。我应该在哪里设置容器的初始状态?
class QuestionnairesContainer extends Component {
static getStores() {
return [QuestionnairesStore];
}
static calculateState(prevState) {
return {
questionnairesList: QuestionnairesStore.getState().questionnairesList,
pagingObject: prevState.pagingObject
};
}
constructor(props) {
super(props);
this.state = {
pagingObject: someData
};
}
render() {
return (
<section>
</section>
);
}
}
export default Container.create(QuestionnairesContainer);
答案 0 :(得分:0)
我找到了通量GitHub的解决方案。
static calculateState(prevState) {
const init = prevState ? {} : {
pagingObject: someData,
};
return {
...init,
questionnairesList: QuestionnairesStore.getState().questionnairesList
};
}
constructor(props) {
super(props);
}