Skip to content
Merged
10 changes: 5 additions & 5 deletions src/hooks/useRefEffect/ko/useRefEffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
## 인터페이스

```ts
function useRefEffect(
callback: (element: Element) => CleanupCallback | void,
function useRefEffect<E extends HTMLElement>(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the generic naming — I agree that the current source Element shadows the global DOM type, so a rename makes sense

However, our convention avoids abbreviations, so E might not be the best fit. What do you think about using a full name likeTargetElement or RefElement instead? Or if you have another idea, happy to hear it!

If we go with a rename, it'd be great to update both the source and docs together so they stay in sync.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used abbreviations based on the useLongPress and mouseDoubleClick documentation, but both hooks are now deprecated🤔

RefElement looks good :)

We will update both the source code and documentation!

callback: (element: E) => CleanupCallback | void,
deps: DependencyList
): (element: Element | null) => void;
): (element: E | null) => void;
```

### 파라미터

<Interface
required
name="callback"
type="(element: Element) => CleanupCallback | void"
type="(element: E) => CleanupCallback | void"
description="요소가 설정될 때 실행되는 콜백 함수예요. 이 함수는 정리 함수를 반환할 수 있어요."
/>

Expand All @@ -31,7 +31,7 @@ function useRefEffect(

<Interface
name=""
type="(element: Element | null) => void"
type="(element: E | null) => void"
description="요소를 설정하는 함수예요. 이 함수를 <code>ref</code> 속성에 전달하면, 요소가 변경될 때마다 <code>callback</code>이 호출돼요."
/>

Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useRefEffect/useRefEffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
## Interface

```ts
function useRefEffect(
callback: (element: Element) => CleanupCallback | void,
function useRefEffect<E extends HTMLElement>(
callback: (element: E) => CleanupCallback | void,
deps: DependencyList
): (element: Element | null) => void;
): (element: E | null) => void;
```

### Parameters

<Interface
required
name="callback"
type="(element: Element) => CleanupCallback | void"
type="(element: E) => CleanupCallback | void"
description="A callback function that is executed when the element is set. This function can return a cleanup function."
/>

Expand All @@ -31,7 +31,7 @@ function useRefEffect(

<Interface
name=""
type="(element: Element | null) => void"
type="(element: E | null) => void"
description="function to set the element. Pass this function to the <code>ref</code> attribute, and the <code>callback</code> will be called whenever the element changes."
/>

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useRefEffect/useRefEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function useRefEffect<Element extends HTMLElement = HTMLElement>(
cleanupCallbackRef.current();
cleanupCallbackRef.current = () => {};

if (element == null) {
if (element === null) {
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strict null check element === null will not catch undefined values, which could cause the callback to be executed with undefined. The original loose equality check == null was correct as it handles both null and undefined cases. This change could introduce bugs when the element is undefined.

Suggested change
if (element === null) {
if (element == null) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since instance is of type T | null as in React CallbackRef Type, I don't think we need to check for undefined. What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! — since the type is T | null, === null works correctly here.

That said, our codebase uses == null as the convention (see mergeRefs, mergeProps, debounce, etc.), so how about keep it consistent and revert to == null??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to stick to the existing conventions!

return;
}

Expand Down
Loading