英文:
Vite with react - Imported function doesn't appear in the browser
问题
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?
英文:
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?
答案1
得分: 0
Your function Nav isn't returning anything. Also the return is wrong.
import React from "react";
function Nav() {
return (
<>
<h1>导航栏放在这里</h1>
</>
);
}
export default Nav;
英文:
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;
答案2
得分: 0
- 在 Nav.jsx 文件中使用这段代码:
import React from "react";
function Nav() {
return <h1>导航栏放在这里</h1>;
}
export default Nav;
- 在 App.jsx 中如下导入:
import Nav from "./Componentes/Navbar";
英文:
- use this code in Nav.jsx file
import React from "react";
function Nav() {
return <h1>Navbar goes here</h1>;
}
export default Nav;
- and inport as below in App.jsx:
import Nav from "./Componentes/Navbar";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论