skip to Main Content

enter image description hereI am new to react, although my app is working just fine but my app.jsx is showing an error. A redline appears beneath the react word and when I am hovering the mouse pointer over it, it is saying "react is define but never used" Can any one of you help me, i am attaching the screenshot below

I am very new to react, i don’t understand why there is an redline beneath the react word although my app is working just fine. I don’t understand why my editor is showing a redline beneath the word react, it is saying that react was defined but never used.

2

Answers


  1. To resolve this, you have two options:

    Keep the import and ignore the warning:
    You can keep your current import import React from ‘react’ and simply ignore the warning. Your app will continue to work fine.
    Remove the import (recommended for newer React versions):
    If you’re using React 17 or later with a modern build setup, you can remove the React import entirely. The JSX transform in newer versions doesn’t require you to import React for just using JSX.

    Your App.jsx file would then look like this:

    function App() {
      return (
        <div>
          <h1>Hello World</h1>
        </div>
      );
    }
    
    export default App;

    This warning is just a linter suggestion and doesn’t affect your app’s functionality. It’s trying to help you keep your code clean by pointing out unused imports.

    Login or Signup to reply.
  2. To resolve this, either use React in your code or remove the import statement if it’s unnecessary.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search