当我的动作中的函数被调用时,除非我取出调度,否则它不会工作

When a function inside my actions is called it won't work unless I take out the dispatch

我正在使用 React Redux,我正在尝试在我的操作文件中的另一个函数中调用一个函数。问题是它只有在我使用函数的调度部分时才有效。

我不想从 askForUser() 调用 updateToken(),但只有当我从 updateToken() 中获取调度部分时它才会起作用。另外,当我从 askForUser() 调用 askForUser() 时,它也不起作用。

const updateToken = (token) => dispatch => {
    console.log(token)

    dispatch({
        type: UPDATE_TOKEN,
        payload: token
    })
}


const askForUser = (token) => dispatch => {
    dispatch({ type: ASKING_FOR_DATA })
    axios.get(API.GET_USER, {
        params: {
            token
        }
    }).then((response) => {
        if (response.data.status === 1) {
            dispatch({ type: ASK_FOR_USER, payload: response.data.user })
        } else if (response.data.status === 2) {
            updateToken(response.data.token)
            //console.log(hola2())
        } else {
            NotificationManager.error('Error consiguiendo usuario')
            dispatch({ type: ERROR_HANDLER })
        }
    }).catch((err) => {
        console.log(err)
        dispatch({ type: ERROR_HANDLER })
    })
}

你必须 dispatch :

 else if (response.data.status === 2) {

   dispatch(updateToken(response.data.token)); // dispatch the function here

 }