Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ref applied to Functional Component #3084

Open
1 task done
jridgewell opened this issue Mar 25, 2021 · 1 comment · May be fixed by #4549
Open
1 task done

Ref applied to Functional Component #3084

jridgewell opened this issue Mar 25, 2021 · 1 comment · May be fixed by #4549
Labels

Comments

@jridgewell
Copy link
Contributor

jridgewell commented Mar 25, 2021

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
AMP is using a function ref to support functional Components exposing a useImperativeHandle API on some (not all expose an API) components. For Components that don't call useImperativeHandle, Preact is calling the function with the VNode, which is inconsistent with React.

Importantly, we don't know if the Component will or won't expose an API, so we must always pass the ref function down. If the Component doesn't expose an API, we expect ref to be unused.

To Reproduce

Function ref: https://codesandbox.io/s/heuristic-easley-mwdzm?file=/index.js
Object ref: https://codesandbox.io/s/objective-kirch-v78v4?file=/index.js

Steps to reproduce the behavior:

  1. Pass a function ref to a functional Component
  2. Don't use useImperativeHandle inside that Component
  3. See error

Expected behavior

Refs shouldn't be applied when using functional Component that doesn't call useImperativeHandle.

@JoviDeCroock
Copy link
Member

Currently this is the expected behaviour in 11 we would stop applying refs to functional and class components and forward them by default. In X this is a behaviour that is expected as React does it as well

@JoviDeCroock JoviDeCroock linked a pull request Feb 13, 2025 that will close this issue
1 task
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants