2

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.

1
  • So, what's stopping you from using import { useEffect } from 'react';? Commented Apr 7, 2023 at 13:55

1 Answer 1

8

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"
      }
    ]
  }
],
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.