-
-
Notifications
You must be signed in to change notification settings - Fork 974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutation: Optimistic updates #3938
Comments
final prevState = state;
try {
state = <your optimistic update>
return await repo.post();
} catch (err) {
state = prevState;
} |
Ops. I should have thought of that myself. 😅 Perhaps this could be automated so that Riverpod restores the previous state in the event of a mutation.error? |
We certainly could have a |
The main challenge is that we can only automate it for immutable state. And there's also the addec challenge of "what if the state changed in the meantime". Reverting it could revert more than needed. |
I do believe that this should be the default setting, because if an update is not optimistic, this would result in a noop. |
I don't think that should be the default. But about race conditions, we could throw if the state is mutated outside of the mutation while the optimistic mutation is pending. |
How to implement optimistic updates with Riverpod mutations?
The text was updated successfully, but these errors were encountered: