Skip to main content

getSafeWindow

A function that safely retrieves the Window object.

Prevents errors that occur when trying to access the window object in a server environment, and safely returns the window object only in client environments.


Code

🔗 View source code


Interface

typescript
function getSafeWindow(): Window

Usage

typescript
import { getSafeWindow } from '@modern-kit/utils';

const window = getSafeWindow();
window.addEventListener('click', () => {
console.log('click');
});