Last active
April 10, 2021 11:26
-
-
Save ilxanlar/b98f6cb9b3dd387d8941a1fa4b468271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useMutation(yourMutationFunction, { | |
// Before the mutation starts | |
async onMutate() { | |
/* 1. Stop the queries that may affect this operation */ | |
/* 2. Modify cache to reflect this optimistic update */ | |
/* 3. Return a snapshot so we can rollback in case of failure */ | |
const context = { ... } | |
return context | |
}, | |
// Mutation throws an error | |
onError(error, newItem, context) { | |
/* Rollback the changes using the snapshot */ | |
}, | |
// After mutation ends successfully | |
onSuccess() { | |
/* Refetch or invalidate related queries */ | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment