NextUI Table, useState 如何编辑行?

NextUI Table, useState How do I edit a row?

提问人:StackMyFlow 提问时间:11/17/2023 最后编辑:StackMyFlow 更新时间:11/17/2023 访问量:20

问:

您好,我遇到了 NextUI Table 和 useState 的问题。

我看到stackoverflow上有一个类似的问题,但我无法让该示例与新版本的NextUI一起使用。

从本质上讲,我希望在表格的每一行中都有一个编辑按钮,并在用户单击它时弹出一个包含这些值的模式。

我正在关注文档:https://nextui.org/docs/components/table#custom-cells

export default function App() {
 
  const [activeRow, setActiveRow] = useState();

 const renderCell = useCallback(
    (item: FactoriesTableRow, columnKey: React.Key) => {
      const cellValue = item[columnKey as keyof FactoriesTableRow];

      switch (columnKey) {
case "actions": {
          return (
              <Tooltip content="Edit user">
                <span className="text-lg text-default-400 cursor-pointer active:opacity-50">
                  <button
                    onClick={() => {
                      setActiveRow(item);
                      onOpen();
                    }}
                  >
                    <EditIcon />
                  </button>
                </span>
              </Tooltip>
          );
        }
        default:
          return cellValue;
      }
    },
    []
  );

return (
    <>
      <Table>
        <TableHeader columns={Columns}>
          {(column) => (
            <TableColumn key={column.key}>{column.label}</TableColumn>
          )}
        </TableHeader>
        <TableBody items={items} >
          {(item) => (
            <TableRow key={item.id}>
              {(columnKey) => (
                <TableCell>{renderCell(item, columnKey)}</TableCell>
              )}
            </TableRow>
          )}
        </TableBody>
      </Table>
      <EditModal
        isOpen={isOpen}
        onOpenChange={onOpenChange}
        activeRow={activeRow}
      />
    </>
  );
}

我遇到的问题是,如果我调用setActiveRow(item),我会收到一条大约半公里长的非常神秘的错误消息。然后,模态加载正确的数据,但是这个来自地狱的错误消息是什么,它与useState有什么关系吗?

警告:内部 React 错误:缺少预期的静态标志。请通知 React 团队。 EditModal@webpack-internal:///(app-pages-browser)/./components/EditModal.tsx:30:58 FacilitiesTable@webpack-internal:///(app-pages-browser)/./components/tables/Tables.tsx:33:36 分区 $8927f6f2acc4f386$导出$250ffa63cdc0d034</Node<@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-primitive/dist/index.mjs:44:58 $921a889cee6df7e8$export$99c2b779aa4e8b8b@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-presence/dist/index.mjs:28:56 $69cb30bb0017df05$export$bd905d70e8fd2ebb<@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-tabs/dist/index.mjs:156:121 _c4@webpack-internal:///(app-pages-browser)/./components/ui/tabs.tsx:47:35 分区 $8927f6f2acc4f386$导出$250ffa63cdc0d034</Node<@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-primitive/dist/index.mjs:44:58 Provider@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-context/dist/index.mjs:47:72 $69cb30bb0017df05$export$b2539bed5023c21c<@webpack-internal:///(app-pages-browser)/./node_modules/@radix-ui/react-tabs/dist/index.mjs:54:236 分区 分区 InnerLayoutRouter@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:242:18 RedirectErrorBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/redirect-boundary.js:72:9 RedirectBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/redirect-boundary.js:80:24 NotFoundBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/not-found-boundary.js:62:62 LoadingBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:338:76 ErrorBoundary@webpack-internal:///(应用页面浏览器)/./node_modules/next/dist/client/components/error-boundary.js:130:67 InnerScrollAndFocusHandler@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:152:9 ScrollAndFocusHandler@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:227:37 RenderFromTemplateContext@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/render-from-template-context.js:15:44 OuterLayoutRouter@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:348:220 InnerLayoutRouter@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:242:18 RedirectErrorBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/redirect-boundary.js:72:9 RedirectBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/redirect-boundary.js:80:24 NotFoundBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/not-found-boundary.js:62:62 悬念 LoadingBoundary@webpack-internal:///(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js:338:76

reactjs react-hooks nextui

评论


答: 暂无答案