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 do I disable SSR for a particular route/component? #1891

Open
zaykhere opened this issue Sep 2, 2022 · 2 comments
Open

How do I disable SSR for a particular route/component? #1891

zaykhere opened this issue Sep 2, 2022 · 2 comments

Comments

@zaykhere
Copy link

zaykhere commented Sep 2, 2022

❓Question

So, I have a component which makes use of a package that wants to use window object. Now, window object is undefined (I'm guessing this is due to the fact that window object is not available in server-side).

So, to counter this issue, I'll need to disable SSR for that particular component. The question is, how do I do that?

@balsa-lazarevic
Copy link

Hi @zaykhere, you cannot just disable SSR for a route, you should handle the error in your code. Just use something like typeof window !== "undefined" to check whether your code is running serverside.

@MatthewPattell
Copy link

@zaykhere hi. You can import component with loadable or lazy. E.g.

It's will rendered only on client and only if located in viewport

<LazyLoad>
     <MyComponent />
</LazyLoad>

or use loadable

if you have react 18, also Suspense available.

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

3 participants