Skip to content

Conversation

wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Sep 13, 2025

Overview

This PR introduces two distinct improvements to the useRefEffect hook:

  1. Documentation and interface now include a generic type parameter, enhancing type safety and flexibility when using the hook with different HTMLElement types. This change improves developer experience by providing accurate typing information in the docs and type signatures.

  2. The implementation has been updated to perform a strict null check (element === null) rather than a loose check. This strengthens type narrowing in TypeScript, ensuring that the callback is only called when a valid element is set, and avoids potential bugs related to falsy values.

Together, these changes make the hook safer to use and better documented without changing its external behavior.

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@Copilot Copilot AI review requested due to automatic review settings September 13, 2025 07:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the useRefEffect hook by adding generic type parameters to improve type safety and strengthening the null check implementation. The changes improve developer experience through better TypeScript typing while maintaining the same external behavior.

  • Added generic type parameter <E extends HTMLElement> to the hook interface for better type safety
  • Updated null check from loose equality (== null) to strict equality (=== null) for more precise type narrowing
  • Updated documentation to reflect the new generic type interface

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/hooks/useRefEffect/useRefEffect.ts Strengthened null check from loose to strict equality
src/hooks/useRefEffect/useRefEffect.md Updated interface documentation to include generic type parameter
src/hooks/useRefEffect/ko/useRefEffect.md Updated Korean documentation to match generic type interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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
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?

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5bdb4ff) to head (a8ecfc4).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #273   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         1093      1093           
  Branches       324       324           
=========================================
  Hits          1093      1093           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants