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

Bound Mutate does not update state but useSWRMutation does #2965

Closed
wctiger opened this issue May 16, 2024 · 2 comments
Closed

Bound Mutate does not update state but useSWRMutation does #2965

wctiger opened this issue May 16, 2024 · 2 comments

Comments

@wctiger
Copy link

wctiger commented May 16, 2024

Bug report

Description / Observed Behavior

I am using swr with object keys to fetch a data source which can be updated in backend and I am giving users an ability to manually refresh. I've been using SWR's mutation features to implement it. The mutate function from useSWR return does not update the state, while the trigger function from useSWRMutation updates it. However, both calls are firing network requests.

Note in my use case the key did not change and I am just running an manual refresh.

Expected Behavior

Both calls should update state

Repro Steps / Code Example

See https://stackblitz.com/edit/vitejs-vite-fvuflg?file=src%2FApp.jsx

Additional Context

SWR version: * || ^2.2.5

@koba04
Copy link
Collaborator

koba04 commented May 22, 2024

isLoading is only updated during initial loading, so in this case, isValidating would be what you expect.
In your example, data returned from useSWR is not being accessed, so re-rendering doesn't happen.

@wctiger
Copy link
Author

wctiger commented May 22, 2024

isLoading is only updated during initial loading, so in this case, isValidating would be what you expect. In your example, data returned from useSWR is not being accessed, so re-rendering doesn't happen.

Thanks it is helpful - just educated myself more with the documentations on the point you mentioned here:
https://swr.vercel.app/docs/advanced/performance#dependency-collection
https://swr.vercel.app/docs/advanced/understanding.en-US#combining-with-isloading-and-isvalidating-for-better-ux

Closing the thread

@wctiger wctiger closed this as completed May 22, 2024
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