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

utils.isReturningJSX is returning false all the time #741

Closed
zachguo opened this issue Aug 4, 2016 · 4 comments
Closed

utils.isReturningJSX is returning false all the time #741

zachguo opened this issue Aug 4, 2016 · 4 comments
Labels

Comments

@zachguo
Copy link

zachguo commented Aug 4, 2016

I found this when I was working on a new rule. #736

All following SFC nodes are considered not returning JSX by utils.isReturningJSX(node). utils.isReturningJSX(node.parent) & utils.isReturningJSX(node.body) are both returning false too.

const Hello = (props, context) => {
  return <div>Hello {context.name}</div>;
};
const Hello = function(props, context) {
  return <div>Hello {context.name}</div>;
};
const Hello = (props, {name}) => {
  return <div>Hello {name}</div>;
};
@zachguo zachguo changed the title isReturningJSX is returning false all the time utils.isReturningJSX is returning false all the time Aug 4, 2016
@zachguo
Copy link
Author

zachguo commented Aug 4, 2016

A new util function like isStatelessFunctionalComponent to handle SFC detection may be needed. SFC detection has been discussed and requested many times: #512 #578 #672
And the util function should be unit tested.

@ljharb
Copy link
Member

ljharb commented Aug 4, 2016

Certainly isReturningJSX should be fixed.

Separately, an isSFC function should be added, but that doesn't have to be done at the same time.

@mjackson
Copy link
Contributor

As I suggested here I believe the only way to create an accurate isStatelessFunctionalComponent method would be to check if a function is ever actually used as the first argument in React.createElement. Otherwise you're going to get a bunch of false positives with methods that return some JSX but aren't intended to be SFCs.

@ljharb
Copy link
Member

ljharb commented Feb 2, 2022

We've done lots of improvements here, and I believe this original issue is fixed.

If there's further bugs, please open a new issue (or better, a PR with failing tests), and we'll address it.

@ljharb ljharb closed this as completed Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants