【问题标题】:Error: Component definition is missing display name错误:组件定义缺少显示名称
【发布时间】:2021-11-22 14:53:48
【问题描述】:

我有以下代码使用 react-table 钩子。 Vercel 编译显示以下错误消息: 49:15 错误:组件定义缺少显示名称 react/display-name,其中第 49 行在下面的代码中指示。

const tableHooks = (hooks) => {
    hooks.visibleColumns.push((columns) => [
      ...columns,
      {
        accessor: "status",
        Header: "Status",
        Cell: ({ row }) => (  // Line 49
          <h6
            className={classes.editstatus}
            onClick={() => bookingDetailHandler(row.original.brewery_type)}
            value={row.original.brewery_type}
          >
            {row.original.brewery_type}
          </h6>
        ),
      },
    ]);
  };
  const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    page,
    state: { pageIndex, pageSize },
    setPageSize,
    nextPage,
    previousPage,
    canNextPage,
    canPreviousPage,
    pageOptions,
    // state,
    gotoPage,
    pageCount,
    prepareRow,
    flatRows,
  } = useTable(
    {
      columns,
      data,
      // defaultColumn
    },
    tableHooks,
    // useFilters,
    useSortBy,
    usePagination
  );

【问题讨论】:

    标签: reactjs react-table


    【解决方案1】:

    只需将箭头函数切换到命名函数

    {
        accessor: "status",
        Header: "Status",
        Cell: function statusItems({ row }) {
          return (
            <h6
                className={classes.editstatus}
                onClick={() => bookingDetailHandler(row.original.brewery_type)}
                value={row.original.brewery_type}
              >
                {row.original.brewery_type}
              </h6>
          );
        },
      }
    

    【讨论】:

    • 非常感谢您的宝贵时间。改成命名函数后,如何在 ReactTable 实例中声明 statusItems?
    • statusItems是自定义函数,不需要在ReactTable实例中声明
    • 谢谢维塔利。你的建议有帮助
    猜你喜欢
    • 2021-12-13
    • 2020-06-19
    • 2020-07-28
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    相关资源
    最近更新 更多