Skip to content

react/no-multi-comp false positive when wrapping inline stateless with React.memo #2145

Closed
@aaronmccall

Description

@aaronmccall

Given the following code

import React from 'react';

const TestStateless = React.memo(props => (
  <div>{props.children}</div>
));

class Test extends React.Component {
  render() {
    return <TestStateless><p>I am wrapped in TestStateless</p></TestStateless>
  }
}
export default Test;

and rule config,

"react/no-multi-comp": ["error", { "ignoreStateless": true }]

I would expect no error, but I get errors as though ignoreStateless were its default of false.

When I define the stateless component outside React.memo then wrap it,

import React from 'react';

const stateless = props => <div>{props.children}</div>
const TestStateless = React.memo(stateless);

class Test extends React.Component {
  render() {
    return <TestStateless><p>I am wrapped in TestStateless</p></TestStateless>
  }
}
export default Test;

there are no errors.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions