Skip to content
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

how work with mutate #14

Closed
Suro4ek opened this issue Jun 6, 2023 · 3 comments
Closed

how work with mutate #14

Suro4ek opened this issue Jun 6, 2023 · 3 comments

Comments

@Suro4ek
Copy link

Suro4ek commented Jun 6, 2023

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
Copy link
Author

Suro4ek commented Jun 6, 2023

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
Copy link
Member

dkzlv commented Jun 6, 2023

@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
Copy link
Member

dkzlv commented Jun 9, 2023

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

@dkzlv dkzlv closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants