Javascript 反应本机&;Redux-错误:操作必须是普通对象。使用自定义中间件进行异步操作

Javascript 反应本机&;Redux-错误:操作必须是普通对象。使用自定义中间件进行异步操作,javascript,reactjs,react-native,redux,state,Javascript,Reactjs,React Native,Redux,State,我正在尝试使用Redux构建react本机应用程序,我的操作文件导致以下错误: 错误:操作必须是普通对象。使用自定义中间件进行异步操作 有人知道这是怎么回事吗?以下是相关代码: import axios from 'axios' //http client import {API_URL} from '../utils/constants' export const FETCH_USER = 'fetch_user' export const editProfileUser = async

我正在尝试使用Redux构建react本机应用程序,我的操作文件导致以下错误:

错误:操作必须是普通对象。使用自定义中间件进行异步操作

有人知道这是怎么回事吗?以下是相关代码:

import axios from 'axios' //http client
import {API_URL} from '../utils/constants'

export const FETCH_USER = 'fetch_user'

export const editProfileUser = async (email, password, name, location, aboutMe, memberSince, 
   picture) => {
 try{
 const response = await axios({
 method: 'POST',
 url: `${API_URL}/api/get_token`,
 data: {
  email,
  password
 }
 })
 const {token} = response.data
 const userResponse = await axios({
  method: 'POST',
  url: `${API_URL}/api/edit_user_profile`,
  headers: {
    Authorization: `${token}`
  },
  data: {
    name,
    location,
    aboutMe,
    memberSince,
    picture
  }
})

console.log("userResponse.data", userResponse.data)

return (
  {
    type: FETCH_USER,
    payload: {
      token,
      email,
      password
    }
  }
)


} catch(err){
console.log("Exception in actions/user/editProfileUser err", err)
}
}

看起来您正在尝试执行一个异步操作,该操作不是Redux的一部分。您需要在外部处理获取请求,或者使用异步Redux库,如或

你所能做的就是在承诺完成后立即采取行动:

axios({
      method: 'POST',
      url: `${API_URL}/api/edit_user_profile`,
      headers: {
        Authorization: `${token}`
      },
      data: {
        name,
        location,
        aboutMe,
        memberSince,
        picture
      }
    }).then(({token, email, password}) => {
     // Dispatch your action with the values you want to store
     dispatch(editProfileUser(token, email, password))
})
从redux文档:

操作是信息的有效负载,从您的服务器发送数据 应用到您的商店。他们是唯一的信息来源 商店

操作只负责发送数据,不负责检索数据