【问题标题】:Passing object literal styled component传递对象文字样式的组件
【发布时间】:2019-04-15 13:17:48
【问题描述】:

我有类似以下的内容:

functionName = () => {
  const {
    prop1,
    prop2,
    prop3,
  } = this.props;

  const collectionOfProps = {
    'ONE': prop1,
    'TWO': prop2,
    'THREE': prop3,
  }

  return (
    <FirstWrapper>
      collectionOfProps={collectionOfProps}
    </FirstWrapper>
  )
}

在我的FirstWrapper 我有这样的功能

const firstConst = ( {collectionOfProps} ) => firstFunction(
  collectionOfProps[ONE],
  hardCodedValue
)

const firstFunction = (value1, value2) => {
  value1 === something
    ? true
    : false
}

但我目前收到以下控制台错误

ONE is not defined

在这方面的任何帮助都会很棒!

【问题讨论】:

    标签: reactjs ecmascript-6 styled-components react-props


    【解决方案1】:

    ONE 应该作为字符串传递。您似乎将 ONE 作为范围内不存在的变量传递。

    所以

    const firstConst = ( {collectionOfProps} ) => firstFunction(
      collectionOfProps["ONE"],
      hardCodedValue
    )
    

    【讨论】:

    • 哦,是的! facepalm 谢谢!猜猜这可能是一个值得其他人学习的好问题
    • @zeduke 以后你可能会想起这个?
    猜你喜欢
    • 2021-12-10
    • 2023-01-04
    • 2022-11-15
    • 2022-10-24
    • 2016-12-24
    • 1970-01-01
    • 2019-04-30
    • 2019-07-25
    • 2016-06-14
    相关资源
    最近更新 更多