mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
23 lines
787 B
TypeScript
23 lines
787 B
TypeScript
export const noop = () => {};
|
|
|
|
export function on<T extends Window | Document | HTMLElement | EventTarget>(
|
|
obj: T | null,
|
|
...args: Parameters<T['addEventListener']> | [string, Function | null, ...any]
|
|
): void {
|
|
if (obj && obj.addEventListener) {
|
|
obj.addEventListener(...(args as Parameters<HTMLElement['addEventListener']>));
|
|
}
|
|
}
|
|
|
|
export function off<T extends Window | Document | HTMLElement | EventTarget>(
|
|
obj: T | null,
|
|
...args: Parameters<T['removeEventListener']> | [string, Function | null, ...any]
|
|
): void {
|
|
if (obj && obj.removeEventListener) {
|
|
obj.removeEventListener(...(args as Parameters<HTMLElement['removeEventListener']>));
|
|
}
|
|
}
|
|
|
|
export const isBrowser = typeof window !== 'undefined';
|
|
export const isNavigator = typeof navigator !== 'undefined';
|