skip to Main Content

I am trying to make a basic React project and I thought I was doing everything right until I tried to import my generalInput file into my App file. I am being told that my generalInput is being declared but never read. I even put my code into AI to see if I could get help but it was confused as well.

Here is the code:

import generalInput from "./generalInput";
import "./styles.css";

export default function App() {
  return (
    <>
      <generalInput name="John" />
    </>
  );}
export default function generalInput(name) {
  return (
    <>
      <label>{name}</label>
      <input type="text" />
    </>
  );
}

2

Answers


  1. maybe you need to reread React docs or ?X compilers jsx, tsx never accept a component whose first character is number or lowercase please capitalize first letter like like this otherwise it will be treated as regular html tag

    import GeneralInput from "./generalInput";
    import "./styles.css";
    
    export default function App() {
      return (
        <>
          <GeneralInput name="John" />
        </>
      );
    }
    
    Login or Signup to reply.
  2. The first and basic thing is that when you create a component the first letter of its name should be capital

    import GeneralInput from "./generalInput";
    import "./styles.css";
    
    export default function App() {
      return (
        <>
          <GeneralInput name="John" />
        </>
      );}
    

    here is your updated component

    export default function GeneralInput(name) {
      return (
        <>
          <label>{name}</label>
          <input type="text" />
        </>
      );
    }
    

    Hope this will fix your issue

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