“Vite with React – 导入的函数不会出现在浏览器中”

huangapple go评论59阅读模式
英文:

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 &quot;./Componentes/Navbar&quot;;

function App() {
  return (
    &lt;&gt;
      &lt;Nav /&gt;
    &lt;/&gt;
  )
}

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

import React from &quot;react&quot;;

function Nav() {
    &lt;&gt;
        &lt;h1&gt;Navbar goes here&lt;/h1&gt;
    &lt;/&gt;
}

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 &quot;react&quot;;

function Nav() {
    return (
        &lt;&gt;
            &lt;h1&gt;Navbar goes here&lt;/h1&gt;
        &lt;/&gt;
    );
}

export default Nav;

答案2

得分: 0

  1. 在 Nav.jsx 文件中使用这段代码:
import React from "react";
function Nav() {
    return <h1>导航栏放在这里</h1>;
}
export default Nav;
  1. 在 App.jsx 中如下导入:
import Nav from "./Componentes/Navbar";
英文:
  1. use this code in Nav.jsx file
import React from &quot;react&quot;;
function Nav() {
    return &lt;h1&gt;Navbar goes here&lt;/h1&gt;;
}
export default Nav;
  1. and inport as below in App.jsx:
import Nav from &quot;./Componentes/Navbar&quot;;

huangapple
  • 本文由 发表于 2023年5月24日 19:42:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定