nanostores / query

⚡️ Powerful data fetching library for Nano Stores. TS/JS. Framework agnostic.
MIT License
229 stars 10 forks source link

how work with mutate #14

Closed Suro4ek closed 1 year ago

Suro4ek commented 1 year ago

as I understand it, I should just return fetch inside createMutatorStore, but is it possible to make a request to the mutate as in swr there in mutate useSWR('/api/user', fetcher)?

Suro4ek commented 1 year ago

for example, I make a request, but I don't get an error from 500 codes


    return fetch(url, {
        method: 'POST',
        body: JSON.stringify(data)
    }).then(res => res.json())
dkzlv commented 1 year ago

@Suro4ek Hey there! 👋

First, here's a repro of the mutation that catches errors. Try clicking on +5 or -5 buttons, you'll see that in 20% of cases it reverts the changes to the cache and shows an error. So if something doesn't return errors to you, can you please provide a repro on stackblitz?

Second is this:

but is it possible to make a request to the mutate as in swr there in mutate useSWR('/api/user', fetcher)?

I'm not sure what you're talking about here 🤔 If you're talking about bound mutator, then yes, we have it. But we typically advice to use mutation stores (useSWRMutation in SWR terms). Again, feel free to expand on your thoughts in code/stackblitz/whatever.

dkzlv commented 1 year ago

I'll close it for now, feel free to reopen if something's missing/unclear.