Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/hooks/useVisibilityEvent/ko/useVisibilityEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function useVisibilityEvent(
required: false,
defaultValue: 'false',
description:
'true이면, 현재 가시성 상태로 마운트 시에 즉시 콜백이 호출돼요.',
'true이면, 현재 가시성 상태로 마운트 시에 즉시 콜백이 호출돼요. <br />: 초기값은 <code>false</code>이에요.',
Comment thread
wo-o29 marked this conversation as resolved.
},
]"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useVisibilityEvent/useVisibilityEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function useVisibilityEvent(
required: false,
defaultValue: 'false',
description:
'If true, the callback is invoked immediately upon mounting with the current visibility state.',
'If true, the callback is invoked immediately upon mounting with the current visibility state. <br />: The initial value is <code>false</code>.',
Comment thread
wo-o29 marked this conversation as resolved.
},
]"
/>
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useVisibilityEvent/useVisibilityEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useCallback, useEffect } from 'react';
import { useEffect } from 'react';

import { usePreservedCallback } from '../usePreservedCallback/index.ts';

type Options = {
immediate?: boolean;
Expand Down Expand Up @@ -27,9 +29,7 @@ type Options = {
*/

export function useVisibilityEvent(callback: (visibilityState: 'visible' | 'hidden') => void, options: Options = {}) {
const handleVisibilityChange = useCallback(() => {
callback(document.visibilityState);
}, [callback]);
const handleVisibilityChange = usePreservedCallback(() => callback(document.visibilityState));
Comment thread
wo-o29 marked this conversation as resolved.

useEffect(() => {
if (options?.immediate ?? false) {
Expand Down
Loading