我是 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
组件中,我在克隆它们时覆盖了子样式
最佳答案
我确定 Container
和 ClickableText
组件的父级有问题。
请检查父组件 StackView
。如果您覆盖子样式,那么这就是这个烂摊子的根本问题。
祝你好运。
关于javascript - React 子组件具有未定义的 props.style,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40133471/