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 ?
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')
})
2
Answers
It seems that your object
user.user
is not aserializable, but data that you return to the slice should be aserializable.you can have a look here how to work with Non-Serializable data in Redux.
see also Use with React-Redux-Firebase
The user object is a non-serializable value.
Redux requires that all values stored in the state are serializable, you can converted the data to a JSON string using JSON.stringify().