从同一动作文件中的另一个动作中调用一个动作

我正在构建一个应用程序,后端工作正常(邮差已确认),但出现了下一个问题。

dbactions.js Redux操作文件

// LOAD USER
export const loadUser = () => async dispatch => {    
  try {
    const res = await axios.get('http://localhost:5000/api/auth');
    dispatch({
      type: USER_LOADED,payload: res.data
    }); 
  } catch (error) {
    dispatch({ type: AUTH_ERROR })
  }
}

export const register = ( formData ) => async dispatch => {
  try {
    const config = {
      headers: {
        'Content-Type': 'application/json'
      }
    }
    const res = await axios.post( 'http://localhost:5000/api/users',formData,config )
    dispatch({
      type: REGISTER_SUCCESS,payload: res.data,})

    loadUser();
  } catch (error) {
    dispatch({
      type: REGISTER_FAIL,payload: error.response.data.msg
    })
  }
}

当我在注册操作中致电LOADUSER()时,它报错,尝试了调度(LOADUSER())但没用。

showOoOoOoOo 回答:从同一动作文件中的另一个动作中调用一个动作

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2982829.html

大家都在问