React的子组件有未定义的props.style
React Child component has undefined props.style
我是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
试图谷歌这个问题,但一无所获。有人能帮帮我吗?由于
迈克尔的回答被发现了。问题是在我的StackView
组件中,我在克隆它们时重写了子样式
我敢肯定Container
和ClickableText
组件的父组件有问题。
请检查父组件StackView
。如果你重写了children样式,那么这就是问题的根源。
好运。
如果你的组件不是无状态功能组件,那么你需要使用this.props.style
来访问该属性。
更多的组件类型在这里:https://tylermcginnis.com/functional - - vs -无状态组件功能组件- vs -无状态组件- 630 fdfd90c9c
相关文章:
- document.getElementById.style.backgroundImage not working
- 如何从reactjs中的按钮向函数传递props
- 为什么我可以'不要使用xx[this.index].style.display?它's说“;无法读取属性
- HEAD中LINK和STYLE元素的求值顺序
- 如何让firefox使用style['attribute name']=设置样式属性
- React.cloneElement:传递新的孩子或复制props.children
- 更改SVG'style'元素
- "无法获取属性'的值;style'"当试图在IE中更改样式时
- placeHolder id未使用style.display显示
- 重置transform:rotate()而不调用-webkit transition:style
- 正在获取props值的子字符串-React
- 如何使主体采用等同于 style=“background-color: returnBlue()” 的样式属性,其中 r
- Vue.js-插值错误-如何将样式修改为v-bind:style
- Javascript style.background在IE中不起作用
- 从ReactJS中的amplificPopup访问@props
- 为什么当我分配给element.style时,我的元素的样式没有改变
- nextProps 总是与 this.props 相同,即使 props 在 componentWillReceiveP
- This.props.dispatch not a function - React-Redux
- Greasemonkey:当style=“display: none;”发生变化时如何做某事
- React的子组件有未定义的props.style