skip to Main Content

I am writing a python + React contact app using vite and flask and i keep experiencing this error that says ‘React’ is defined but never used.This is my code:

This is App.jsx

import { useEffect, useState } from 'react'
import './App.css'
import ContactList from './ContactList';

function App() {
  const [contacts, setContacts] = useState([]);


  useEffect(() => {
    fetchContacts()
  }, []);

  const fetchContacts = async () => {
    const response = await fetch("http://127.0.0.1:5000/contacts");
    const data = await response.json();
    setContacts(data.contacts);
  };

  return (
    <ContactList contacts={contacts} />
  );
}

export default App

This is contact.jsx

import React from 'react'

const ContactList = ({contacts}) => {
  return (
    <div>
        <h2>Contacts</h2>
        <table>
            <thead>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {contacts.map((contact) => (
                    <tr key={contact.id}>
                        <td>{contact.firstName}</td>
                        <td>{contact.lastName}</td>
                        <td>{contact.email}</td>
                        <td>
                            <button>Update</button>
                            <button>Delete</button>
                        </td>
                    </tr>
                ))}
            </tbody>
        </table>
    </div>

  )
}

export default ContactList;

This is my package.json

{
  "name": "frontend",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0,eslint src/**/*.js src/**/*.jsx",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.2.56",
    "@types/react-dom": "^18.2.19",
    "@vitejs/plugin-react": "^4.2.1",
    "eslint": "^8.56.0",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.5",
    "vite": "^5.1.4"
  }
}

What could be the issue?

So I run "npm i" on the frontend to import React but for some reason unknown to me, i keep having this error

2

Answers


  1. Could you screenshot the error? It’s probably the first line in contact.jsx. You can delete it since React no longer requires it to be imported.

    Login or Signup to reply.
  2. Remove import React from ‘react’ statement from contact.jsx file

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