【发布时间】:2025-12-12 15:40:01
【问题描述】:
我正在尝试使用 Redux 构建一个 react-native 应用程序,但我收到以下来自我的 Actions 文件的错误:
错误:动作必须是普通对象。使用自定义中间件进行异步操作
有人知道这里发生了什么吗?以下是相关代码:
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)
}
}
【问题讨论】:
标签: javascript reactjs react-native redux state