-
Notifications
You must be signed in to change notification settings - Fork 10
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
Handling mutation errors on per-store level #28
Comments
Just wanted to pop in here to make a case for potentially adding an We have a use-case, where we're letting the user bulk-delete things like so: const { mutate: deleteThing } = useStore($deleteThing);
const handleBulkDelete = (values) => {
Promise.all(
(selectedOptions).map(async (eachOptionToDelete) => {
await deleteThing({
thingID: eachOptionToDelete.id,
});
}),
);
}; And since some can error, some can succeed, it would be good to handle errors on a per-request level, which means we would either need |
@martinmckenna Your particular code sample seems to be a strange usage of mutations 🤔 I'll set aside the fact that you perform N API operations instead of one (maybe, that's just a limitation of your backend, even though it's quite horrible, sometimes that's life). I particularly dislike the usage of the same mutation store in N parallel operations. const $bulkDeleteThing = createMutationStore<{ id: string }[]>(
async ({ data: selectedOptions }) => {
return Promise.all(
selectedOptions.map((opt) =>
// That should be a direct API call, not mutation call
deleteThing({ thingID: opt.id }).catch(() => {
// There you have it! That's your per-operation `onError` right there.
})
)
);
}
); So I think your particular use case is more or less covered by current API. You just need to use promises creatively. |
@martinmckenna Btw, after giving it a good thought, I think that your specific code will break in some of future releases 😬 Read issue #34 I just created for more details. |
First mentioned in #27.
The proposed solutions are:
onError
tocreateMutationStore
interface. Maybe, same should be applied tocreateFetcherStore
?createMutationStore
, ifmutate
should throw or not.The text was updated successfully, but these errors were encountered: