So I have redux-thunk
set up and when I call the updateUser(userInfos)
action, it returns a promise to update the server with those infos.
But sequentially I need to update the local state with those infos too, and if I wait for UPDATE_USER_FULFILLED
, the effect of my action is not instantaneous, which feels weird for the user.
I thought of reducing the UPDATE_USER_PENDING
action to update the local state before the server response arrives with up-to-date data (which should be the same so no re-rendering), but unfortunately, the payload
of UPDATE_USER_PENDING
action is null
:(
Ain't there a way to load it with some data, which would allow instant UI response before server return?
Could be something like:
export function updateUser(user) {
return {
type: UPDATE_USER,
payload: {
promise: userServices.update(user),
localPayload: user,
}
}
}
but I'm guessing this is not available?
For now, the only solution I see is to create a UPDATE_USER_LOCAL
action which would do the local action in parallel with the server call. But this is not very elegant and much heavier.
Thanks for the help