next-isServer
A simple nextjs plugin to check if getInitialProps
was loaded on the server or the client.
How to use
Install
First you need to install the package locally to your project:
npm i next-isserver --save
Create your server file if you have not yet already:
// server.jsconst next = const isServer = const app = const handler = // With expressconst express = app // Without expressconst createServer = app
Update your package.json
file scripts if needed:
"scripts":
Client
In any of your files that use the getInitialProps
function, you can access isServer
from the query
property like so:
Component static async { const isServer = query return isServer } { return <div> This page was thispropsisServer ? '': 'NOT' rendered on the server </div> }
License
MIT