Skip to content

Commit

Permalink
feat: 优化useResizeObserver,避免在非浏览器环境下isSupported不能正确检测;避免没意义的deep监听 (#186
Browse files Browse the repository at this point in the history
)
  • Loading branch information
XiaoDaiGua-Ray authored Mar 9, 2024
1 parent 8da6a65 commit 1e6c68a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/hooks/src/useResizeObserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ResizeObserverCallback = (

export interface UseResizeObserverOptions {
/**
* The box the observer is observing changes to.
* The box the observer is observing changes to.
* The default is content-box.
*
* @default 'content-box'
Expand All @@ -28,7 +28,7 @@ export default function useResizeObserver(
options?: UseResizeObserverOptions,
): UseResizeObserverReturnType {
const { box = 'content-box', ...argsOptions } = options ?? {}
const isSupported = ref('ResizeObserver' in window)
const isSupported = ref(window && 'ResizeObserver' in window)
let ob: ResizeObserver | null
const modelTargets = computed(() =>
Array.isArray(target) ? target.map(curr => getTargetElement(curr)) : [getTargetElement(target)],
Expand Down Expand Up @@ -61,7 +61,6 @@ export default function useResizeObserver(
{
flush: 'post',
immediate: true,
deep: true,
},
)

Expand Down

0 comments on commit 1e6c68a

Please sign in to comment.