Skip to content

[Bug]: False positive for destructuring-assignment with useContext #3520

Closed

Description

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

This library is amazing 🙏

Just wanted to share that in latest (7.32.0) I'm getting a linting error for a non-destructured assign from useContext. Please correct me if I'm wrong but I don't this this is valid in every case because the context value might be a nullable object.

Expected Behavior

Here's a simple example of what I think should be a valid case:

import { useContext } from 'react';

const MyComponent = (props) => {
  const foo = useContext(aContext);
  return <div>{foo?.test}</div>
};

eslint-plugin-react version

v7.32.0

eslint version

v8.31.0

node version

v16.14.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions