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

标签 javascript css reactjs web inline-styles

我是 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/

相关文章:

html - 如何使元素保持悬停能力但让点击穿过它?

javascript - 无法读取未定义的属性 'rejected' | ReactJS

javascript - 为什么我应该在 AngularJS 中使用工厂?

javascript - 我怎样才能异步运行两个正在运行的jquery?

html - 无法将标题内的文本居中

reactjs - 无法使用 docker 容器运行 react 应用程序

javascript - 以 redux-form 形式添加多个 <Fields/>

reactjs - Redux Form 7.4.2,如何防止在组件渲染时提交表单并显示错误

javascript - 浏览器内javascript需要节点样式吗?

javascript - FormArray(在 Angular6 中): return empty array