preact
preact copied to clipboard
Ref applied to Functional Component
- [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:
- Pass a function ref to a functional Component
- Don't use
useImperativeHandle
inside that Component - See error
Expected behavior
Refs shouldn't be applied when using functional Component that doesn't call useImperativeHandle
.