How can I lazy load this library? #4755
-
Hi I am currently implementing loading optimizations of my Next.js' powered website. I found that lazy loading What is the correct way to achieve this? I am currently using the Provider/Context pattern in
const MyApp = ({ Component, pageProps }: AppProps) => {
const [queryClient] = useState(() => new QueryClient());
// ...
return (
<QueryClientProvider client={queryClient}>
<Component {...pageProps} />
</QueryClientProvider>
)
} And then inside a component Even if I would just keep the provider (since the provider is probably tiny) I cannot have e.g. What is the best way to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
the provider is tiny, but the maybe one way to do it would probably be to put the However, this would mean that every page that has react-query would need to be rendered inside this component, and the queryClient would not be shared. I don't see this as benefitial |
Beta Was this translation helpful? Give feedback.
the provider is tiny, but the
new QueryClient()
is not. It contains the caches and all the logic, it's most of the bundle size.maybe one way to do it would probably be to put the
QueryClientProvider
into a component that your ender in your App, and then have this component be lazy loaded.However, this would mean that every page that has react-query would need to be rendered inside this component, and the queryClient would not be shared.
I don't see this as benefitial