[英]How to access prop in child of child component
我有三個組件說 A、B、C。我需要將樣式從 A 組件傳遞到 C 組件作為道具。 在 A 組件中,我提到了
const customeStyle : Istyle
{
overFlow: 'auto'
}
現在我需要在組件 C 中獲取此屬性作為 IStyle。
在 A 組件中,我作為
<A {...this.props.customStyle} />
我已經創建了界面
interface IProps
{
style : IStyle
}
在 B 組件中
Class B extends React.Component<IProps>
<C { ...this.props.customStyle}
在 C 組件中
Class C extends React.Component<IProps>
如何將 props 值作為 Istyle 獲取,因為我需要動態地給出溢出屬性。
你需要考慮你正在傳遞什么。 當你傳播一個對象時,你使用它的鍵,即你不是將樣式作為道具傳遞,而是作為它的屬性傳遞。
<A {...this.props.customStyle} />
是相同的
<A overFlow="auto" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.