在我的父组件中,我有:
getCatalogItems(id = 12, sessionId = "anythingForNow", filterBy = []) {
return this.props.actions.getCatalogInfo(id, sessionId, filterBy)
.then(catalogItemsReturned=> {
console.log("CATALOG ITEMS RETURED", catalogItemsReturned) //always undefined
})
}
componentWillMount() {
console.log("component will mount called")
this.getCatalogItems();
}
由于某种原因, render
此组件的功能被调用为5-6次,即使我根本没有改变任何状态。
是什么原因?我怎么能解决它?
我的触发操作是通过API调用获得结果,但出于某种原因,我没有在then
功能
getCatalogItems
部分调度操作中获取结果
这就是我的行动:这有什么问题吗?
export function getCatalogItemsSuccess(catalogItems) {
return {
type: types.LOAD_CATALOG_SUCCESS,
catalogItems //courses:courses
}
}
export function getCatalogInfo(id = 12, sessionId="anythingForNow", filterBy = []){
return function (dispatch) {
return catalogProductsAPI.getProductsByCategoryId(id, sessionId, filterBy)
.then(
catalogItems =>{
console.log("catalog INFO in actinnnnnnnnnnnnnnnnn", catalogItems) // I get the right results here
dispatch(getCatalogItemsSuccess(catalogItems));
}).catch(err=>{
console.log("errorin get catalog", err);
throw(err);
}); //the function from API would return a promise
};
}