Skip to content

isServer ​

isServer is a utility function that checks if the code is running on the server. It returns true in SSR (Server-Side Rendering) environments where window is undefined, and false in client-side environments.

Interface ​

ts
function isServer(): boolean;

Parameters ​

This function does not accept any parameters.

Return Value ​

  • boolean

    true if running in a server environment (SSR), false otherwise.

Example ​

tsx
if (isServer()) {
  // SSR-safe code
  return null;
}

// Client-only code
window.addEventListener('resize', handleResize);

Released under the MIT License.