为什么 Flux 的 calculateState 方法中的 prevState 参数为空?
Why is prevState argument null in calculateState method in Flux?
我在构造函数 this.state = {};
中设置了状态,但是 calculateState
方法中的 prevState
参数为空。我应该在哪里设置容器的初始状态?
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);
我找到了关于通量的解决方案 GitHub。
static calculateState(prevState) {
const init = prevState ? {} : {
pagingObject: someData,
};
return {
...init,
questionnairesList: QuestionnairesStore.getState().questionnairesList
};
}
constructor(props) {
super(props);
}
我在构造函数 this.state = {};
中设置了状态,但是 calculateState
方法中的 prevState
参数为空。我应该在哪里设置容器的初始状态?
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);
我找到了关于通量的解决方案 GitHub。
static calculateState(prevState) {
const init = prevState ? {} : {
pagingObject: someData,
};
return {
...init,
questionnairesList: QuestionnairesStore.getState().questionnairesList
};
}
constructor(props) {
super(props);
}