我有一个简单的减速器。我在 combineReducers 和 createStore 中使用它。我想使用 async thunk 来使用 axios 获取数据。我看不到的是如何在没有 createSlice 函数的情况下使用 thunk。你能指点我什么地方或解释一下吗?
import { createAction } from '@reduxjs/toolkit'
export const setMyData = createAction('myData/setMyData')
export const initialState = {
myData: []
};
const myDataReducer = (state = initialState, action) => {
switch (action.type) {
case setMyData.type:
return {
...state,
myData: action.payload
};
default:
return { ...state };
}
};
export default myDataReducer;