-
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
Why Doesn't mutate
return a value on Error or Promise Rejections?
#27
Comments
Hi, thanks for the awesome lib! I'm working on the same team as Martin. I would expect there are a few reasonable choices for this.
Ideally, we get to specify something like that in the createMutatorStore init. What do you think? |
mutate
return a value on 400+?mutate
return a value on Error or Promise Rejections?
Will this work for you? Seems simple enough. const { mutate } = useStore($createThing)
const handleAddNewThing = async () => {
const response = await mutate({ hello: 'world' });
if ($createThing.value.error) { /* show toast */ }
} Since you don't need reactivity in the callback, and See the thing is that I also very much dislike when things are overly complicated or have too many options. As an example of behavior I don't like: Apollo Client. If you destructure On a broader topic, I'd suggest moving toast state to nanostores as well. If you have everything in one state manager, you'll see how simple it is to solve such issues. In this particular case I'd most probably introduce a global |
That makes sense. I like this lib for its simplicity, I can read the impl in one sitting. I agree implicit throw vs not throw is a debugging headache. I've seen libs just take that behavior as a parameter, whether to reraise, wrap the error, or do something else with it. I really loved using Async Monitors: https://ocaml.org/p/async_kernel/latest/doc/Async_kernel/Monitor/index.html#val-try_with We'll try out what you recommend, though. |
hey @dkzlv this seems to work, but it seems like the We'll go with this for now, but I think even having an React query also exposes an option like this: https://tanstack.com/query/latest/docs/framework/react/guides/mutations#mutation-side-effects |
@martinmckenna Oh, both As for your suggestion, I'll make another issue for it, and will close this one for now. Feel free to ping if something doesn't work for you! |
Hi sorry for all the GitHub issues, I'm having another issue that i'm finding I may need to create a workaround for
I have code the roughly looks like this:
Now the issue here is that the only real way to show my toast notification is listen to
error
and do it in auseEffect
like so:So my question is, why can't I just get access to the error at the time I call
mutate
? Even react themselves say this is not a good way of reacting to changes:https://react.dev/learn/you-might-not-need-an-effect#sharing-logic-between-event-handlers
Essentially what would be awesome is an option that will return the error inside this
catch
block:https://github.com/nanostores/query/blob/main/lib/main.ts#L365
The text was updated successfully, but these errors were encountered: