Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-adults-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"overlay-kit": patch
---

Export `isClientEnvironment` function for mocking
8 changes: 6 additions & 2 deletions packages/src/utils/create-use-external-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { useLayoutEffect } from 'react';
import { createEmitter } from './emitter';

const emitter = createEmitter();
function useClientLayoutEffect(...args: Parameters<typeof useLayoutEffect>) {

export function isClientEnvironment() {
const isBrowser = typeof document !== 'undefined';
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';

if (!isBrowser && !isReactNative) return;
return isBrowser || isReactNative;
}

function useClientLayoutEffect(...args: Parameters<typeof useLayoutEffect>) {
if (!isClientEnvironment()) return;
useLayoutEffect(...args);
}

Expand Down