![](/img/trans.png)
[英]TS Lint Error; Type X is not assignable to type 'IntrinsicAttributes & RefAttributes<any>'
[英]how to pass array of object into component, Type x is not assignable to type 'IntrinsicAttributes & x'
數組類型看起來像MyType: {name: string, age: number}[]
,組件中的道具類型相同
<Content data={arrOfObj} /> // warning
const Content: React.FC<MyType> = (data) => {...}
如何正確地將其傳遞給組件? 而且我也認為組件中的道具類型實際上不等於MyType。 要訪問數據,您需要編寫以下data.data
,但是由於 ts 認為 data 是一個數組,所以不能這樣寫
這可能是你想要的
<Content data={arrOfObj} /> // warning
const Content: React.FC<{ data: MyType }> = ({ data }) => {...}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.