0

Hello I am a new programmer, recently I started coding in react but I have this problem with my JavaScript code. Import is not working.

import React from 'react';
import './App.css';
import { hello } from '/components/hello.js';

function App() {
  return (
    <div className="App">
      <header>
      <p>
        <hello></hello>
      </p>
      </header>
    </div>
  );
}

export default App;

This here is my app.js file

import React from 'react';

export default function hello(){
    return <h1>Hello user</h1>;
}

This here is my hello.js file(It is located inside my components folder) Can anyone tell me why import is not working??

0

2 Answers 2

2

Change this:

    import React from 'react';

    export default function Hello(){
    return <h1>Hello user</h1>;
}

To this:

    import React from 'react';

    export function Hello(){
    return <h1>Hello user</h1>;
}

If you want to leave it as a default function then import it like this instead:

import Hello from '/components/Hello.js';

Also, it is best practice to capitalize component names. <Hello />

Sign up to request clarification or add additional context in comments.

Comments

1

Try using default import instead of name import because in your hello.js you are setting up for default. Also your path for hello.js is right? Try ./hello.js

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.