Skip to content

Add a rule for detecting unnecessary stable dependencies #89

@Thodor12

Description

@Thodor12

Hey, I like your plugin and it works great. Although I have one addition which would be useful.
Some actions like dispatch actions (from useState) are referred to as stable references. They do not change and thus are not needed as dependencies.
Although it makes no difference if you add it, technically it's just unnecessary code.

A rule to detect this would be nice, for example in the code:

const [loading, setLoading] = useState(true);
const startLoading = useCallback(() => setLoading(true), [setLoading]); // setLoading is not needed because it is a stable reference

According to the react documentation regarding hooks this should apply to the following 3 hooks:

  • useState
  • useReducer
  • useId

https://reactjs.org/docs/hooks-reference.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions