如何将styledcomponent中的prop传递给stylerule?

时间:2019-02-25 03:39:28

标签: reactjs css3 styled-components

我在我的reactjs应用程序中使用styledcomponents。在其中一个组件中,我有一个媒体规则:

@media (max-width: 1450px)
{
  padding-right: ${props => (props.meta.count > 0 ? '6px' : '0')};
}

这个meta.count属性确实存在,但是当我运行该应用程序时,我得到了:

TypeError: Cannot read property 'count' of undefined

渲染开始如下:

const { lastUpdated, meta } = this.props;

元道具通过redux选择器加载:

const mapStateToProps = state => ({
  meta: getAlertsMeta(state),
});

如何避免这种情况/解决此问题?

0 个答案:

没有答案