Skip to content

set-state-in-effect not consistent with eslint plugin #95

@einarq

Description

@einarq

I run a fairy strict eslint setup on any code that is being committed:

  rules: {
    ...reactHooks.configs['recommended-latest'].rules,
    // https://github.com/facebook/react/blob/3640f38/compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts#L807-L1111
    'react-hooks/todo': 'error',
    // other useful rules:
    'react-hooks/capitalized-calls': 'error', 
    'react-hooks/hooks': 'error', 
    'react-hooks/rule-suppression': 'error', 
    'react-hooks/syntax': 'error', 
    'react-hooks/unsupported-syntax': 'error', 
  }

Still, code like this goes through without complaints.

  const [image, setImage] = useState(initImage);
  useEffect(() => {
    setImage(initImage);
  }, [initImage]);

When I run the React Doctor however, it points out that this should be derived during render instead.

Perfectly valid to highlight this, but curious how this is being detected by the Doctor when the Compiler doesn't complain?

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