Open menu dropdown
isClient
Check whether the code is running in a browser environment (has a `document`).
Usage
ts
import { isClient } from '@maz-ui/utils'
if (isClient()) {
document.body.classList.add('hydrated')
}API
ts
function isClient(): booleanReturns true if document is defined, false otherwise (e.g. SSR, Node.js, Web Workers).
Notes
- The opposite is
isServer. - Implemented as a one-liner:
typeof document !== 'undefined'. - Prefer this over checking
process.client(Nuxt) orimport.meta.env.SSR(Vite) when you want a framework-agnostic check.