Q: How to execute code client-side only
See original GitHub issueI have a callback route in my application that receives access token from auth process in URL hash fragment. I’d like to parse it and save into redux store. I used to get it through window.location.hash
before I switched to next, but this is not available when page renders server-side (also the hash fragment apparently isn’t sent to server, so I can’t parse it there).
Is there any way to restrict some code to execute only in client-side? Or is there any other way to achieve this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (10 by maintainers)
Top Results From Across the Web
Next.js: run code only on the server side or client side in Next.js
In your page components, you can execute code only in the server-side or on the client-side, but checking the window property.
Read more >How to use client-side only packages with SSR in Gatsby and ...
This is how server-side rendering works: the server we requested the page from executes all the code in a node server: your browser...
Read more >How is client-side code run on server-side? - Stack Overflow
It is the environment where the code is being executed. In your server you have a container that is interpreting you C# code...
Read more >Render client-side only component in Next.js
How to make code run only on client-side with Next.js? To my surprise, this is surprisingly easy. Next.js inherited the process.browser ...
Read more >Using Client-Side Only Packages - Gatsby
On occasion, you may need to use a function or library that only works client-side. This usually is because the library in question...
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
@vanniewelt You can always look at
process.browser
…edit by @Timer:
@vanniewelt You can always look at
typeof window
…You can also use the
componentDidMount
lifecycle method of React. It’s not called server side.