Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable linter rules to use `useEffect` instead of `React.useEffect` (named export instead of full export)

In our codebase we always wanna use

import { useEffect } from 'react';

instead of

import React from 'react';
// use in code as `React.useEffect`

Is it possible to achieve it with eslint longer rules? If yes then how?

Are there existing solutions? And if there isn't existing solution then how to write a custom one?

We wanna use such rules only for the react dependency.

like image 423
valerii15298 Avatar asked Nov 18 '25 11:11

valerii15298


1 Answers

use no-restricted-imports to limit the import of React (default):

"no-restricted-imports": [
  "error",
  {
    "paths": [
      {
        "name": "react",
        "importNames": ["default"],
        // "message": "some messages for who import 'React' accidentally"
      }
    ]
  }
],
like image 126
Jerryh001 Avatar answered Nov 20 '25 00:11

Jerryh001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!