我對反應非常陌生,我正試圖通過亂搞來學習圖書館。
我在將物件傳遞給另一個組件時遇到問題。我創建了一個包含 2 個字串變數、1 個函式和 1 個 int 的物件陣列。
我正在嘗試在 Grid 容器(Material UI 框架)中填充它。
當我將物件傳遞給另一個反應組件時,它以未定義的形式到達。我試圖通過首先將其記錄到控制臺來檢查我是否傳遞了一個有效的物件,并且它是有效的。
我還嘗試參考接收物件的組件中的屬性,但瀏覽器控制臺會拋出Uncaught TypeError: Cannot read properties of undefined (reading 'person').
有誰知道為什么它被發送為未定義?
個人串列.js:
const personListe = [
{
firstName:'testFirstname',
lastName:'testLastName',
getFullName:function()
{
return `${this.firstName} ${this.lastName}`
},
age:28
}
]
export default function PersonList() {
return (
<>
<Grid container spacing={3}>
{personListe.map((person) => {
return(
<Grid item xs={3} key={person.firstName}>
<PersonCard person={person} />
</Grid>
)
})}
</Grid>
</>
);
}
人卡.js:
export default function PersonCard({props})
{
return (<>
{console.log(props)}
</>)
}
uj5u.com熱心網友回復:
所述PersonCard組件臨危道具物件,其包括在其內部的人物件。
export default function PersonCard({person})
{
return (
<>
{console.log(person)}
</>
)
}
或者
export default function PersonCard(props)
{
return (
<>
{console.log(props.person)}
</>
)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/408295.html
標籤:
上一篇:在父項中匯入SVG并傳遞給子項
