首页 > 解决方案 > 将箭头函数返回给组件

问题描述

我有下面的箭头功能,我希望能够将这里的所有内容返回给组件。我如何退回所有东西?是否可以使用导出功能?下面的代码位于一个 js 文件中。

const myTester = props => {
  [
    {
      title: props.intl.formatMessage({
        id: "ren_past_due"
      }),
      icon: (
        <EventBusy
          color="#cc2444"
          style={style}
          className="icon-box-icon-image material-icons"
        />
      ),
      color: "#C60C30",
      expiresBefore: today()
    },
    {
      title: props.intl.formatMessage({
        id: "ren_zerotothree_months"
      }),
      icon: (
        <Today
          color="#f2b826"
          style={style}
          className="icon-box-icon-image material-icons"
        />
      ),
      color: "#F0AB00",
      expiresAfter: today(),
      expiresBefore: today().add(3, "months")
    }
  ].map(item => {
    if (item.expiresBefore) {
      item.expiresBefore = item.expiresBefore.format("Y-MM-DD");
    }
    if (item.expiresAfter) {
      item.expiresAfter = item.expiresAfter.format("Y-MM-DD");
    }
    return item;
  });
};

标签: reactjs

解决方案


在第 2 行return的前面添加一个。[

返回数组的简写() => ([1, 2, 3]);

返回 object的简写() => ({ name: 'shorthand' });


推荐阅读