I created thunk by redux toolkit "createAsyncThunk" and i do some async operations here
export let Login: any = createAsyncThunk("authPage/Login",
async ({values, action}: any, {dispatch, rejectWithValue}) => {
try {
let response = await AuthAPI.Login(values)
if (response.data.resultCode === 0) {
let responseFromAuthMe = await HeaderAPI.AuthMe()
if (responseFromAuthMe.data.resultCode === 0) {
- - - - - - dispatch(HeaderLogin()) - - - - - - - - -
}
} else {
if (response.data.resultCode === 10) {
let response = AuthAPI.GetCaptcha()
dispatch(getCaptcha(response))
}
action.setStatus({error: response.data.messages})
}
} catch (err: any) {
return rejectWithValue(err.response.data)
}
})
but one moment i need use another thunk like "HeaderLogin" :
export let HeaderLogin: any = createAsyncThunk("authPage/HeaderLogin",
async ({}, {dispatch}) => {
let responseFromAuthMe = await HeaderAPI.AuthMe()
if (responseFromAuthMe.data.resultCode === 0) {
let {id, email, login} = responseFromAuthMe.data.data;
//TODO check 4 arg - isLogin
dispatch(setAuthUserData({id, email, login}))
let responseLogin = await HeaderAPI.Login(login)
return responseLogin.data.items.filter((u: any) => {
if (id === u.id) {
return u
}
})
}
})
but thunk is not called. maybe have any way that calls thunk?
How i can use thunk inside another thunk in Redux?