Skip to content

fix: support forwardRef with out of line argument #430

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

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

motiz88
Copy link
Contributor

@motiz88 motiz88 commented Feb 11, 2020

Enables handlers that support forwardRef (defaultProps and Flow type handling) to work when the argument to forwardRef is a reference to a function defined outside of the forwardRef call:

import React from 'react';
const ComponentImpl = ({ foo = 'bar' }, ref) => <div ref={ref}>{foo}</div>;
React.forwardRef(ComponentImpl);

This is achieved by reusing resolveToValue.

Note that this does not fix the rebinding case, which I intend to tackle separately:

import React from 'react';
let ComponentImpl = ({ foo = 'bar' }, ref) => <div ref={ref}>{foo}</div>;
ComponentImpl = React.forwardRef(ComponentImpl); // resolveToValue resolves here :/

Copy link
Collaborator

@danez danez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @motiz88, nice to see you again. Thanks for the PR. lgtm

@danez danez merged commit b5e6d97 into reactjs:master Feb 13, 2020
@motiz88 motiz88 deleted the non-inline-forwardref branch February 13, 2020 00:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants