gpt4 book ai didi

reactjs - Redux 操作类型是 PROBE_UNKNOWN_ACTION

转载 作者:行者123 更新时间:2023-12-04 00:33:58 27 4
gpt4 key购买 nike

我正在调用 requestLoadOrders获取我需要的订单。我正在发送类型:REQUEST然后是 SUCCESSFAILURE .获取成功,因为我的订单在 redux 开发工具的有效负载中,但我在 reducer 中收到的操作是 @@redux/PROBE_UNKNOWN_ACTION_z.r.p.l.z .我找到了一个关于这个的线程 here ,但是我似乎找不到我做错了什么?
redux dev-tools
Action .js

import {
LOAD_ORDERS_REQUEST,
LOAD_ORDERS_SUCCESS,
LOAD_ORDERS_FAILURE
} from './constants';

import { fetchOrders } from '../../api';

export const requestLoadOrders = () => {
return (dispatch, getState) => {
dispatch({ type: LOAD_ORDERS_REQUEST });
fetchOrders().then(orders => {
dispatch({ type: LOAD_ORDERS_SUCCESS, payload: orders });
}).catch(error => {
console.error(error);
dispatch({ type: LOAD_ORDERS_FAILURE, payload: error });
});
};
};
reducer .js
import {
LOAD_ORDERS_REQUEST,
LOAD_ORDERS_SUCCESS,
LOAD_ORDERS_FAILURE
} from './constants';

const initialState = {
orders: []
};

const orderReducer = ( state = initialState, { payload, type }) => {
switch (type) {
case LOAD_ORDERS_REQUEST :
return state;
case LOAD_ORDERS_SUCCESS :
return { ...state, orders: payload};
case LOAD_ORDERS_FAILURE :
return { ...state, error: payload.error};
default :
return state;
}
};

export default orderReducer;
我的 Action 被正确调度,但我认为 reducer 接收其数据存在问题。因此,我还添加了我的商店和组合 reducer 文件。
store.js
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import createHistory from 'history/createBrowserHistory';
import thunk from 'redux-thunk';
import makeRootReducer from './reducers';

export const history = createHistory();

const initialState = {}
const enhancers = [];
const middleware = [ routerMiddleware(history), thunk ];

if (process.env.NODE_ENV === 'development') {
const devToolsExtension = window.devToolsExtension;

if (typeof devToolsExtension === 'function') {
enhancers.push(devToolsExtension());
}
}

const composedEnhancers = compose(
applyMiddleware(...middleware),
...enhancers
);

const store = createStore(
makeRootReducer,
initialState,
composedEnhancers
);

export default store;
reducers.js
import { combineReducers } from 'redux';
import orderReducer from '../modules/Order/reducer';

export const makeRootReducer = asyncReducers => {
return combineReducers({
order: orderReducer,
...asyncReducers
});
}

export default makeRootReducer;

最佳答案

我发现了我的错误。我应该执行 makeRootReducer通过在 createStore() 中的单词后添加括号来发挥作用.
更新了createStore() 的一部分store.js 到:

const store = createStore(
makeRootReducer(),
initialState,
composedEnhancers
);
是修复。

关于reactjs - Redux 操作类型是 PROBE_UNKNOWN_ACTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46346850/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com