-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Does SWR supports code and data preloading #108
Comments
When you enable Suspense it will
The idea of the suspense mode is that you never receive data as undefined, your component got suspended and you handle the fallback using React.Suspense instead. You can check how it works starting here https://github.com/zeit/swr/blob/master/src/use-swr.ts#L448 It doesn’t handle code preloading |
react-query has a |
You could do that using mutate. import { mutate } from "swr";
mutate("/api/resource/1", {}, true); The last You could also actually fetch the data and then run mutate. import { mutate } from "swr";
const data = await fetch("/api/resource/1").then(res => res.json();
mutate("/api/resource/1", data, false); In this case since we already fetched the data we tell |
brilliant! i'm totally wrapping that up into a util |
actually, digging into the source a bit, I don't think using |
@tamagokun it does. Because it will set the cache before component mounts. Although we’re working on another option to make prefetching even more easier and faster (as I explained here #11 (comment)). |
I see, looking at those examples in the comment in this thread, the first mutate wouldn't start the fetch until the hook was created, but the 2nd one would definitely work. Looking forward to see what comes out of #11 ✌️ |
When you enable suspense , how do SWR fetches both data and code parallelly to support code and data preloading
The text was updated successfully, but these errors were encountered: