[英]Redux-Toolkit createAsyncThunk Dispatch is showing as undefined
Using Redux-Toolkit, I am trying to use ThunkAPI & dispatch inside an createAsyncThunk
but I am getting rejected because of type error.使用 Redux-Toolkit,我尝试在 createAsyncThunk 中使用
createAsyncThunk
和调度,但由于类型错误而被拒绝。 Not sure how to resolve this.不知道如何解决这个问题。
my store:我的商店:
export const store = configureStore({
reducer: rootReducer,
middleware: [...getDefaultMiddleware()],
});
my Action:我的行动:
export const tester = createAsyncThunk(
'tester',
async (testData, {dispatch}) => {
await dispatch(load(true));
const final = await someExternalFunc(testData)
return final;
}
);
but, I am getting output as但是,我得到 output 作为
Any help will be really appreciated.任何帮助将不胜感激。
According to your comment, you are not calling the thunk right.根据您的评论,您没有正确调用 thunk。
Calling test()
returns an action, then you should dispatch the action:调用
test()
返回一个动作,然后你应该调度这个动作:
const fetchTodo = createAsyncThunk("todo/fetchTodo", async (args, thunkAPI) => {
console.log(thunkAPI, "thunkAPI");
const response = await todoAPI();
return JSON.stringify(response);
});
dispatch(test(testData));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.