only render a component on client-side
See original GitHub issueI’m trying to use react-select
and got an error throw document is not defined
. I assume this is because it’s trying to render the component on the server side and there’s no document.
What’s the best way to only render a specific component only on the client side?
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Render client-side only component in Next.js
If you are familiar with Next.js then you will know it is the React SSR (server-side rendering) framework created by Vercel.
Read more >How to Client-Side-Render a Component in Next.js
The trick is so simple, actually: When we render something on the server, the window object isn't available to our code. Why? Well,...
Read more >How do I make a client-side only component for GatsbyJS?
How do I create a component for Gatsby that will load on the client-side, not at build time? I created this one and...
Read more >Rendering: Server and Client Components - Next.js beta docs
Client Components are rendered on the client. With Next.js, Client Components can also be pre-rendered on the server and hydrated on the client....
Read more >Client Side Rendering Vs Server Side Rendering in React js ...
In server-side rendering when a user makes a request to a webpage, the server prepares an HTML page by fetching user-specific data and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also ran into this issue. As a way to resolve it used a state variable to ensure the client-side only module is rendered after the first render, like this:
Hope this helps somebody else…
I tried the
canUseDOM
solution and it worked for me. However it is showing a warning, invalid checksum about the markup being generated is different on the client. I think this means React redraws the markup on the client-side. Is it possible to get rid of this warning?