Skip to content

react/no-multi-comp does not seem to work correctly with hooks and ignoreStateless #3005

@elliott-king

Description

@elliott-king

Hello. Hopefully this is the correct place to ask.

I am trying to use the react/no-multi-comp rule:

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

As I understand it, this should NOT allow two components in one file that both use state. For example, I would expect this to fail, but it passes:

import React, { useState } from "react";

const FirstStateful = () => {
  let [bool, setBool] = useState("a");
  return <button onClick={() => setBool(!bool)}>{String(bool)}</button>;
};

const SecondStateful = () => {
  let [counter, setCounter] = useState(1);
  return <button onClick={() => setCounter(counter + 1)}>{counter}</button>;
};

const FirstNotStateful = ({ content }) => {
  return <p>{content}</p>;
};

const SecondNotStateful = ({ content }) => <p>{content}</p>;

Note that if I change the rule to "react/no-multi-comp": ["error", {"ignoreStateless": false}], it does mark everything after the first one as an error.

Additionally, I noticed that there was a recent commit affecting no-multi-comp, so I cloned eslint & retried this with a local dependency, still no dice.

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