繁体   English   中英

React Styled Components 没有获得模式道具

[英]React Styled Components not getting mode props

我正在使用 react 15.6,在我的组件中,我有一种情况,我想将模式道具传递给 mycustomfunction,它返回一些 css。

export const mycustomfunction = (mode=false) => css`
  ${bp('s_up')`
    padding: ${pxToRem(50)} ${mode? flexGridUnit(0.5) : flexGridUnit(1)} !important;
  `}
`;

如果没有通过,这里默认模式应该是假的。 现在我这样称呼它

const MyFields = styled.div.attrs({
  className: 'someclassname',
})`
  ${mycustomfunction(mode)}
`;

并在渲染方法中

<MyFields mode={test.mode}>
  <SomeOtherFields></SomeOtherFields>
</MyFields>

test.mode 为真或假。

它显示错误,因为模式未在 ${mycustomfunction(mode)} 中定义。

代码有什么问题。

任何帮助深表感谢。

您还没有在样式组件本身中使用 prop mode

const MyFields = styled.div.attrs({
  className: "someclassname",
})`
  ${(props) => mycustomfunction(props.mode)}
`;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM