Skip to content

Bug: react-hooks/static-components false positive #35984

@retyui

Description

@retyui

eslint-plugin-react-hooks: 7.0.1

Steps To Reproduce

1.Create react app
2. Add this eslint-plugin-react-hooks plugin
3. Lint the next code

import { FeatureRemovalBuildTime } from '@xxx/build-time-tools/FeatureRemovalBuildTime';
import { PlatformSwitchBuildTime } from '@xxx/build-time-tools/PlatformSwitchBuildTime';
import { isMyFeature } from '@xxx/config/exporter';
import ErrorMessageMT from './ErrorMessageMT';
import ErrorMessageBase from './ErrorMessageBase';

import type { ErrorMessageProps } from './types';

const ErrorMessage = (props: ErrorMessageProps) => {
  'use memo';

  const ErrorMessageView = PlatformSwitchBuildTime.select({
    anyMT:
      FeatureRemovalBuildTime.isMyFeature && isMyFeature()
        ? ErrorMessageMT
        : ErrorMessageBase,
    default: ErrorMessageBase,
  });

  return <ErrorMessageView {...props} />; // Error: react-hooks/static-components
};

export default ErrorMessage;

The current behavior

Eslint will complain that ErrorMessageView was created during the render

The expected behavior

But all values inside if check are stable and valid as in this example: https://react.dev/reference/eslint-plugin-react-hooks/lints/static-components#valid

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions