关于reducer
来源:9-9 redux状态管理:设计详情页reducer

慕虎9189897
2019-08-08
请问老师
对于actionType为FETCH_PRODUCT_DETAIL_SUCCESS的action,
在detail.js中派发时参数为id,在中间件api中派发时参数为response,
但是在reducer中只过滤了action.id,而没有action.response.id,
那么如果是api中派发的这个action时,reducer是否找不到id呢
//detail.js
const fetchProductDetailSuccess = id => ({
type: types.FETCH_PRODUCT_DETAIL_SUCCESS,
id
});
//api.js
return fetchData(endpoint, schema).then(
response => next(actionWith({
type: successType,
response
})),
// 商品详情reducer
const product = (state = initialState.product, action) => {
switch (action.type) {
case types.FETCH_PRODUCT_DETAIL_REQUEST:
return { ...state, isFetching: true };
case types.FETCH_PRODUCT_DETAIL_SUCCESS:
return { ...state, id: action.id, isFetching: false };
case types.FETCH_PRODUCT_DETAIL_FAILURE:
return { ...state, isFetching: false, id: null };
default:
return state;
}
};
写回答
1回答
-
艾特老干部
2019-08-14
你好。不会存在你说的问题的。api.js中间件不会把fetchProductDetailSuccess中传入的id过滤掉的,也就是reducer接收到的action依然有id属性。如果理解上有问题,可以在api中打几个断点,单步调试看看。
00
相似问题