我創建了一個新的 ReactJS 應用程式并將其連接如下。它不起作用。我需要const person呼叫const app,該怎么做?
“應用程式.js”
import './App.css';
const person = () => {
return (
<>
<h1>Name : Shashimal</h1>
<h1>Age : 26</h1>
<h1>Gender : Male</h1>
</>
)
}
const App = () => {
return (
<div className="App">
<person />
</div>
);
}
export default App;
錯誤代碼顯示終端
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
WARNING in [eslint]
src\App.js
Line 3:7: 'person' is assigned a value but never used no-unused-vars
webpack compiled with 1 warning
uj5u.com熱心網友回復:
問題是,當涉及到 React 組件時,您必須使用組件名稱的第一個單詞大寫。所以,使人對人
import './App.css';
const Person = () => {
return (
<>
<h1>Name : Shashimal</h1>
<h1>Age : 26</h1>
<h1>Gender : Male</h1>
</>
);
};
const App = () => {
return (
<div className="App">
<Person />
</div>
);
};
export default App;
uj5u.com熱心網友回復:
如果要在 ReactJS 中使用組件,請將第一個字母大寫:
const Person = () => {
return (
<>
<h1>Name : Shashimal</h1>
<h1>Age : 26</h1>
<h1>Gender : Male</h1>
</>
);
}
uj5u.com熱心網友回復:
所有組件都必須以大寫字母開頭,因此您需要將每個實體從一個人更改為一個人
uj5u.com熱心網友回復:
您需要做的就是重命名
const person = () => ...
至
const Person = () => ...
根據React 檔案,當您創建自己的自定義組件時,組件名稱需要以大寫字母開頭。否則,React 會認為它是一個 HTML 標簽并嘗試將其渲染為一個標簽。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/506958.html
上一篇:變數的Groovy默認值