Skip to content
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

Support 'memo(forwardRef(...' #592

Merged
merged 3 commits into from
Jun 13, 2022
Merged

Conversation

mfazekas
Copy link
Contributor

While forwardRef(...) is already supported memo(forwardRef(...)) doesn't.

@danez
Copy link
Collaborator

danez commented May 28, 2022

Thanks for contributing.

Could you show me an example of what is not working? When I use the example from the test and enter it into the playground I already get the same result as in the test.

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

@mfazekas
Copy link
Contributor Author

mfazekas commented Jun 11, 2022

Thanks for contributing.

Could you show me an example of what is not working? When I use the example from the test and enter it into the playground I already get the same result as in the test.

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

What I see in playground, and in our case also is that this does not work in playground:

import React, {memo,forwardRef} from 'react';


export default memo(forwardRef(({ foo = 'bar' }, ref) => <div ref={ref}>{foo}</div>));

This does work:

import React, {memo,forwardRef} from 'react';


export default React.memo(forwardRef(({ foo = 'bar' }, ref) => <div ref={ref}>{foo}</div>));

So does this:

import React, {memo,forwardRef} from 'react';


export default memo(({ foo = 'bar' }, ref) => <div ref={ref}>{foo}</div>);

I've update the test code in the PR, it still pass, but I'm not sure if this is the proper way of fixing the issue or there is a simpler fix.

@danez
Copy link
Collaborator

danez commented Jun 13, 2022

Thanks again. I looked into this more and discovered that the underlying issue is that isReactBuiltinCall was wrongly detecting forwardRef just because it was imported.

@danez danez merged commit ea9cbeb into reactjs:main Jun 13, 2022
danez added a commit that referenced this pull request Jun 13, 2022
Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com>
danez added a commit that referenced this pull request Jun 13, 2022
Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com>
@danez danez mentioned this pull request Jun 13, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants