Detecting server vs client in NextJS application
There are couple of ways we can detect the NextJS code running on client vs server.
1. Using process.browser
process.browser
return true on client and return undefind on server side.
So we can write the following code.
let isServer = (process.browser)? false : true;
2. Checking window
object
window
object is only available on the browser, so we can do the following
let isServer = (typeof window === 'undefined')? false : true;