preact icon indicating copy to clipboard operation
preact copied to clipboard

Ref applied to Functional Component

Open jridgewell opened this issue 3 years ago • 0 comments

  • [x] 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.

jridgewell avatar Mar 25 '21 21:03 jridgewell