gpt4 book ai didi

javascript - React 子组件具有未定义的 props.style

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:25 24 4
gpt4 key购买 nike

我是 React 的新手。我想创建其中包含多个自定义组件的自定义组件。下面是代码

const { item, to, onClick, width, style, ...otherProps } = props;
const h = width ? (width*IMAGE_RATIO)+'px' : 'auto';
const w = width ? width+'px' : 'auto';
<StackView
style={{ width: w, ...style }}
{...otherProps}
>
<Container
to={to}
onClick={onClick}
item={item}
style={{ width: w, height: h }}
/>
<ClickableText
to={to}
onClick={onClick}
typography={typography.t15}
color={color.red}
activeColor={color.redDark}
style={{ lineHeight: '12px' }}
>
{item.title}
</ClickableText>
</StackView>

Container 组件和 ClickableText 组件内 props.style 得到了 undefined 试图谷歌这个问题但发现没有什么。有人可以帮我吗?谢谢

编辑:

Michael答案被发现了。问题出在我的 StackView 组件中,我在克隆它们时覆盖了子样式

最佳答案

我确定 ContainerClickableText 组件的父级有问题。

请检查父组件 StackView。如果您覆盖子样式,那么这就是这个烂摊子的根本问题。

祝你好运。

关于javascript - React 子组件具有未定义的 props.style,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40133471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com