英文:
How do I properly return a user object from firebase sign using an async thunk and redux slice?
问题
在登录后,我想将用户对象返回给切片,但我一直收到关于不可序列化数据的错误,我该如何正确配置它?<br>
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');
});
}
英文:
After sign in, I wan to return the user object to the slice, but I keep getting an error, about non serializable data, how do I properly configure this ?<br>
export const updateProfileAsync = createAsyncThunk('user/updateProfile', async(user:any,
profile:any)=>{
const response = await updateProfile(user,profile)
return response.user
})
interface
interface userState {
user:User
}
in my slice,
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')
})
答案1
得分: 1
你的 user.user
对象似乎不可序列化,但你返回给 slice 的数据应该是可序列化的。<br>
你可以在这里查看如何在 Redux 中处理不可序列化的数据。<br>
还可以参考与 React-Redux-Firebase 一起使用。
英文:
It seems that your object user.user
is not aserializable, but data that you return to the slice should be aserializable.<br>
you can have a look here how to work with Non-Serializable data in Redux.<br>
see also Use with React-Redux-Firebase
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论