Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ref applied to Functional Component #3084

Open
1 task done
jridgewell opened this issue Mar 25, 2021 · 0 comments
Open
1 task done

Ref applied to Functional Component #3084

jridgewell opened this issue Mar 25, 2021 · 0 comments

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.

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

No branches or pull requests

1 participant