skip to Main Content

I’m using Vite with react, and I would like to show in the browser a imported function by ./Components/Navbar.jsx.

To do this, I created the following script in App.jsx:

import { Nav } from "./Componentes/Navbar";

function App() {
  return (
    <>
      <Nav />
    </>
  )
}

The code with the function (Navbar.jsx) is here:

import React from "react";

function Nav() {
    <>
        <h1>Navbar goes here</h1>
    </>
}

export default Nav()

But the code doesn’t show anything in the browser. Someone could help me?

2

Answers


  1. Your function Nav isn’t returning anything. Also the return is wrong.

    import React from "react";
    
    function Nav() {
        return (
            <>
                <h1>Navbar goes here</h1>
            </>
        );
    }
    
    export default Nav;
    
    Login or Signup to reply.
    1. use this code in Nav.jsx file
    function Nav() {
        return <h1>Navbar goes here</h1>;
    }
    
     2. export default Nav;
    
    and inport as below in App.jsx:
    import Nav from "./Componentes/Navbar";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search