-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Describe the feature you'd love to see
Hi there, I am adding why-did-you-render support to preact, but I found no .render property in the return value of forwardRef.
With the following code:
const MyComponent = forwardRef((props, ref) => {
return <div ref={ref}>MyComponent</div>;
});MyComponent.render will be the function passed to forwardRef in React. See example at https://codesandbox.io/p/sandbox/react-repl-bw2h1. See also the implementation of forwardRef in React.
However, in Preact, there is no render property in MyComponent. And it is wrapped as fn in Forwarded:
preact/compat/src/forwardRef.js
Lines 26 to 31 in 3c556ad
| export function forwardRef(fn) { | |
| function Forwarded(props) { | |
| let clone = assign({}, props); | |
| delete clone.ref; | |
| return fn(clone, props.ref || null); | |
| } |
Additional context (optional)
If we set the original fn passed to MyComponent as render property. Tools such as why-did-you-render can patch the component and intercept original render function, see patchForwardRefComponent
The same for React.memo, can we support .type field as the component being memoed?