英文:
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 'react'
export default function navbar() {
return (
<div> this is navbar component</div>
)}
//app.js
import navbar from './component/navbar';
function App() {
return (
<>
<h1>hello</h1>
<navbar />
</>
);}
export default App;
src\App.js
Line 2:8: 'navbar' 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 (
<div> this is navbar component</div>
)}
//app.js
import Navbar from './component/navbar';
function App() {
return (
<>
<h1>hello</h1>
<Navbar />
</>
);}
first character of custom component name must be Uppercase.
and you dont need import react in navbar.js
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论