Skip to content

fix: support callback forwarded refs#2716

Open
wanxiankai wants to merge 1 commit into
streamich:masterfrom
wanxiankai:fix/ensured-forwarded-ref-callback
Open

fix: support callback forwarded refs#2716
wanxiankai wants to merge 1 commit into
streamich:masterfrom
wanxiankai:fix/ensured-forwarded-ref-callback

Conversation

@wanxiankai

Copy link
Copy Markdown

Description

Fixes #805.

useEnsuredForwardedRef previously treated every forwarded ref as a mutable ref object. Callback refs passed through ensuredForwardRef therefore received a .current property assignment instead of being invoked. This updates the helper to accept React ForwardedRef<T>, assign object refs and callback refs correctly, and call callback refs with null on cleanup.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage
  • Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • Make sure types are fine (yarn lint:types).

Verification

  • yarn test tests/useEnsuredForwardedRef.test.tsx --watchman=false
  • yarn test --watchman=false
  • yarn lint:types
  • ./node_modules/.bin/eslint src/useEnsuredForwardedRef.ts tests/useEnsuredForwardedRef.test.tsx
  • yarn lint (passes with existing warnings)
  • yarn build

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.

useEnsuredForwardedRef not working with callback refs

1 participant