我如何正确地返回一个用户对象从firebase签署使用异步形实转换和redux切片?

dphi5xsq  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(103)

登录后,我想返回用户对象到切片,但我一直得到一个错误,关于不可序列化的数据,我如何正确配置?


的数据

export const updateProfileAsync = createAsyncThunk('user/updateProfile', async(user:any, 
profile:any)=>{
const response = await  updateProfile(user,profile)

return response.user
})

字符串
介面

interface userState {
user:User 
}


在我切片中,

extraReducers:(builder) => {
    builder.addCase(loginAsync.pending, (state,action)=>{
        console.log('pending')
        state.loading = 'pending'
    })
    builder.addCase(loginAsync.fulfilled, (state,action)=>{
        state.loading = 'succeeded'
        console.log('logged in')
        console.log(action.payload)
        state.loginError = ''
    })  
    builder.addCase(loginAsync.rejected, (state,action)=>{
        state.loginError = action.error.message
        state.loading = 'failed'
        console.log('failed')
    })

tvz2xvvm

tvz2xvvm1#

看起来你的对象user.user是不可序列化的,但是你返回到切片的数据应该是aserializable
你可以在这里看看如何在Redux中处理不可序列化的数据。
使用React-Redux-Firebase

相关问题