Skip to content

prefer-stateless-function should detect null in if shorthand return #516

Closed
@inyono

Description

@inyono

With enabled rule prefer-stateless-function, the following does throw a warning although null may be returned:

class If extends Component {
  render() {
    const { condition, ...props } = this.props

    return condition ? <this.props.component {...props} /> : null
  }
}

If we write the result to a variable, though, there is no warning:

class If extends Component {
  render() {
    const { condition, ...props } = this.props

    const component = condition ? <this.props.component {...props} /> : null

    return component
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions