Skip to content

[feat] Prefer React.use over React.useContext #930

Closed
@kachkaev

Description

@kachkaev

Describe the problem

React 19 allows both useContext(MyContext) and use(MyContext) (announcement | docs). Unlike useContext, use can be used conditionally.

Describe the solution you'd like

I’d like to maintain consistency in the codebase and ban useContext because it does a subset of what use can do. It’d be great to have a new auto-fixable rule, e.g. @eslint-react/prefer-use or @eslint-react/no-use-context. This rule would be somewhat similar to @eslint-react/no-forward-ref / @eslint-react/no-context-provider which help to embrace new React 19 features.

Alternatives considered

It is possible to ban useContext via no-restricted-syntax but that’s harder to configure and there is no auto-fix.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions