繁体   English   中英

如何访问子组件的子组件中的道具

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM