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

Added handling in no-multi-comp for forwardRef and memo wrapping comp… #2184

Merged
merged 1 commit into from Aug 15, 2019

Conversation

jenil94
Copy link
Contributor

@jenil94 jenil94 commented Mar 1, 2019

Added handling in no-multi-comp for forwardRef and memo wrapping components declared in the same file.

Fixes #2172

Changes

While checking for isPragmaComponentWrapper code will also check whether the wrapper is wrapping existing component or creating a new one.

If it's is wrapping existing component in extra JSX element then it will be considered as a separate component else it won't.

In the example below the second abc won't be considered as extra component

class StoreListItem extends React.PureComponent {
	// A bunch of stuff here
}
const abc = React.forwardRef((props, ref) => <StoreListItem />)

but in the second case abc will be considered as a separate component

class StoreListItem extends React.PureComponent {
	// A bunch of stuff here
}
const abc = React.forwardRef((props, ref) => <div><StoreListItem /></div>)

…pping components declared in the same file

 - getComponentNameFromJSXElement returns null when node.type is not JSXElement
@jenil94 jenil94 marked this pull request as ready for review March 3, 2019 11:58
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Can you confirm this will fix component detection for any case where a component is passed as the argument to a function?

lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the no-multi-comp branch 3 times, most recently from 7965c22 to 3ddce46 Compare August 15, 2019 22:34
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks! made some final tweaks to get this in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

React ForwardRef in combination with react/no-multi-comp
3 participants