Skip to content

support .render property in the return value of forwardRef #4769

@upupming

Description

@upupming

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:

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions