Content-Length: 284030 | pFad | https://github.com/jsx-eslint/eslint-plugin-react/issues/3568

55 [Bug]: Rule: "react/no-unused-state": TypeError: Cannot read properties of undefined (reading 'references') · Issue #3568 · jsx-eslint/eslint-plugin-react · GitHub
Skip to content

[Bug]: Rule: "react/no-unused-state": TypeError: Cannot read properties of undefined (reading 'references') #3568

Closed
@yurigenin

Description

@yurigenin

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

When the prev state parameter (second parameter) of getDerivedStateFromProps is destructured in-place, the rule react/no-unused-state crashes

static getDerivedStateFromProps = ({value, disableAnimation}: ToggleProps, {isControlled, isOn}: ToggleState) => {

here, isControlled and isOn are destructured state properties.

TypeError: Cannot read properties of undefined (reading 'references')
Occurred while linting /Users/ygenin/src/pillar/src/datagrid/implementation/filtering/filterEditors/DateFilterEditor.tsx:57
Rule: "react/no-unused-state"
    at PropertyDefinition, ClassProperty (/Users/ygenin/src/pillar/node_modules/eslint-plugin-react/lib/rules/no-unused-state.js:388:34)

Expected Behavior

The eslint rule should handle the code without crashing.

The issue seems to be that the stateArg.name on the line below is undefined whereas it is expected to be 'state' or some other name if destructuring is not used.

const argVar = scope.variables.find((x) => x.name === stateArg.name);

eslint-plugin-react version

7.32.2

eslint version

8.2.0

node version

18.12.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/jsx-eslint/eslint-plugin-react/issues/3568

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy