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

Javascript 如何在子组件的子组件中访问道具,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我有三种成分,比如A,B,C。 我需要将样式作为道具从一个组件传递到C组件。 在一个组件中,我提到了 const customeStyle : Istyle { overFlow: 'auto' } 现在我需要在组件C中以IStyle的形式获取这个属性 在一个组件中,我作为 <A {...this.props.customStyle} /> 在B组分中 Class B extends React.Component<IProps

我有三种成分,比如A,B,C。 我需要将样式作为道具从一个组件传递到C组件。 在一个组件中,我提到了

    const customeStyle : Istyle
    {
    overFlow: 'auto'
    }
现在我需要在组件C中以IStyle的形式获取这个属性

在一个组件中,我作为

    <A {...this.props.customStyle} />
在B组分中

   Class B extends React.Component<IProps>

   <C { ...this.props.customStyle}
B类扩展了React.Component

你需要思考你所传递的东西。传播对象时,使用其关键点,即,不是将样式作为道具传递,而是传递其属性

<A {...this.props.customStyle} />

<A overFlow="auto" />


可以有更多属性,如minWidth、maxwidth,这就是为什么我需要包含iStyle的接口作为接口。所以,在主组件A中,我希望传递所有属性,并希望在组件C中访问。这样我就可以访问这个接口,然后简单地访问ISTYLE。如果我们以溢出方式传递道具,那么它将给出类型未定义的typescript错误,所以我们需要使用接口。
<A {...this.props.customStyle} />
<A overFlow="auto" />