Skip to content

Add detection of subRender methods to prefer-stateless-function #1313

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

Closed
wants to merge 1 commit into from

Conversation

jseminck
Copy link
Contributor

Related to: #1235 - though the issue wasn't yet labelled with new rule. If we want it, it's available.

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.

What about closed-over functions (in all component types) that return jsx?

@jseminck
Copy link
Contributor Author

jseminck commented Jul 23, 2017

Could you elaborate with an example, please?

I could only think of this additional case, which indeed we should support as well:

render() {
  const mySubRenderFn = () => <div>{this.state.foo}</div>
  
  return (
    <div>{mySubRenderFn()}</div>
  )
}

@ljharb
Copy link
Member

ljharb commented Jul 23, 2017

function shouldBeComponent() { // this should warn, because it should be a component
  return <div />;
}

function SFC(props) {
  return <div>{shouldBeComponent(props.foo)}</div>;
}
SFC.propTypes = {
  foo: PropTypes.any
};

@ljharb
Copy link
Member

ljharb commented Dec 27, 2018

(Related to #1229)

Let's rebase this and make sure it's still valid?

@jseminck jseminck closed this Jun 21, 2019
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.

2 participants