True if running on the client (browser), false if on server
import { isClient } from '@consumidor-positivo/ts-utils';
if (isClient()) {
// Safe to use window, document, localStorage, etc.
window.localStorage.setItem('key', 'value');
}
// Conditional rendering in React/Next.js
const MyComponent = () => {
if (!isClient()) return null;
return <div>Window width: {window.innerWidth}</div>;
};
Checks if the code is running on the client side (browser) rather than server side. Useful for SSR/SSG applications (Next.js, Gatsby, Astro, etc.) to avoid accessing browser-only APIs like window, document, or localStorage during server rendering.