代码之家  ›  专栏  ›  技术社区  ›  bier hier

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

  •  0
  • bier hier  · 技术社区  · 7 年前

    @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 回复  |  直到 7 年前
    推荐文章