我正在尝试导入导航栏组件并将其用于,但仍然收到未使用的警告?

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

im tryin to import navbar component and used it but still got warn it never used?

问题

"im tryin to import navbar component and used it but why it did'nt show up when i used it and still got warn i never used it?"

"我试图导入导航栏组件并使用它,但为什么在我使用它时它没有显示出来,并且仍然出现警告说我从未使用它?"

//navbar.js
import React from 'react';

export default function navbar() {
return (

这是导航栏组件

)}

//app.js
import navbar from './component/navbar';

function App() {
return (
<>

你好


);}

export default App;

src\App.js
Line 2:8: 'navbar' 被定义但从未使用 no-unused-vars

英文:

im tryin to import navbar component and used it but why it did'nt show up when i used it and still got warn i never used it?

//navbar.js
import React from &#39;react&#39;

export default function navbar() {
return (
&lt;div&gt; this is navbar component&lt;/div&gt;
)}


//app.js
import navbar from &#39;./component/navbar&#39;;

function App() {
return (
&lt;&gt;
&lt;h1&gt;hello&lt;/h1&gt;
&lt;navbar /&gt;
&lt;/&gt;
);}

export default App;


src\App.js
Line 2:8:  &#39;navbar&#39; is defined but never used  no-unused-vars

答案1

得分: 0

你应该将 "navbar" 改为 "Navbar"。

//navbar.js

export default function Navbar() {
return (
<div>这是导航栏组件</div>
)}

//app.js
import Navbar from './component/navbar';

组件名的第一个字符必须是大写的,并且你不需要在 navbar.js 中导入 react。

英文:

you should change navbar to Navbar

//navbar.js

export default function Navbar() {
return (
&lt;div&gt; this is navbar component&lt;/div&gt;
)}


//app.js
import Navbar from &#39;./component/navbar&#39;;

function App() {
return (
&lt;&gt;
&lt;h1&gt;hello&lt;/h1&gt;
&lt;Navbar /&gt;
&lt;/&gt;
);}

first character of custom component name must be Uppercase.

and you dont need import react in navbar.js

huangapple
  • 本文由 发表于 2023年2月10日 11:45:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406732.html
匿名

发表评论

匿名网友

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

确定