Skip to content

Commit 6a96688

Browse files
feat: Export isClientEnvironment function (#179)
* feat: extract client environment detection * Create smooth-adults-tease.md --------- Co-authored-by: Yongbeen Im <been.im@toss.im> Co-authored-by: Yongbeen Im <meis1541@naver.com>
1 parent 6d35a52 commit 6a96688

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/smooth-adults-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"overlay-kit": patch
3+
---
4+
5+
Export `isClientEnvironment` function for mocking

packages/src/utils/create-use-external-events.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { useLayoutEffect } from 'react';
22
import { createEmitter } from './emitter';
33

44
const emitter = createEmitter();
5-
function useClientLayoutEffect(...args: Parameters<typeof useLayoutEffect>) {
5+
6+
export function isClientEnvironment() {
67
const isBrowser = typeof document !== 'undefined';
78
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
89

9-
if (!isBrowser && !isReactNative) return;
10+
return isBrowser || isReactNative;
11+
}
1012

13+
function useClientLayoutEffect(...args: Parameters<typeof useLayoutEffect>) {
14+
if (!isClientEnvironment()) return;
1115
useLayoutEffect(...args);
1216
}
1317

0 commit comments

Comments
 (0)