【问题标题】:Is it possible to create an ES6 Map with a ReactNative component as one of its nodes?是否可以创建一个以 ReactNative 组件作为其节点之一的 ES6 Map?
【发布时间】:2017-04-05 14:11:05
【问题描述】:

我的最终结果应该是这样的:

const SECTIONS = [
  {
    title: 'First',
    content: <ReactComponent />,
  },
  {
    title: 'Second',
    content: <ReactComponent />,
  }
];

但我不确定这是否很糟糕。这是我对此感到困惑和无知的尝试:

return [
  this.props.course.sections
    .map( (section, idx) => {title: section.title, content: <ReactComponent /> } );
]

看起来的麻烦在于,这错误在于它不是正确的哈希,因此它无法识别:。这甚至可以像我试图完成的那样简写吗?

【问题讨论】:

    标签: javascript react-native ecmascript-6


    【解决方案1】:

    您需要用() 包装{} 以使其对象字面量不会阻塞。

    return [
      this.props.course.sections
        .map( (section, idx) => ({title: section.title, content: <ReactComponent /> }) );
    ]
    

    【讨论】:

    • 啊啊啊啊,谢谢你的好先生。谢谢,现在我将不得不等待 10 分钟才能授予您正确答案的标题。非常感谢
    • @Trip 很高兴我能帮上忙 :)
    猜你喜欢
    • 2023-03-14
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多