From 7ad6c9ccd0cb8bcce167a24daada3b31f4eb1c44 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 8 Oct 2023 14:56:08 +0800 Subject: [PATCH 1/2] perf: reduce unnecessary network requset --- src/components/admin/DataTable.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/admin/DataTable.tsx b/src/components/admin/DataTable.tsx index f0928c7..2b43541 100644 --- a/src/components/admin/DataTable.tsx +++ b/src/components/admin/DataTable.tsx @@ -14,7 +14,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { useEffect, useMemo, useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Card } from "../ui/card"; import { ScrollArea } from "@radix-ui/react-scroll-area"; import PageTransition from "../PageTransition"; @@ -51,15 +51,14 @@ export default function DataTable({ const { data, isLoading, error, mutate } = useSWR<{ data: []; total: number; - }>(dynamicUrl, fetcher, { - refreshInterval: 2000, - }); + }>(dynamicUrl, fetcher); useEffect(() => { if (data) { setTotal(data.total); } }, [data]); useEffect(() => { + // 监听从父组件的传来的表格左下角的功能区的动态mutateFlag,从而refetch数据 mutate(); console.log("mutate"); }, [mutateFlag]); From 57f8255c1e4190516e5aaaab9d002fb3049cae9b Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 8 Oct 2023 15:07:02 +0800 Subject: [PATCH 2/2] chore: add some comments --- src/context/ReportDetailsProvider.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/context/ReportDetailsProvider.tsx b/src/context/ReportDetailsProvider.tsx index 70ed6a1..a61e2b0 100644 --- a/src/context/ReportDetailsProvider.tsx +++ b/src/context/ReportDetailsProvider.tsx @@ -52,6 +52,7 @@ export default function ReportDetailsProvider({ const { mutate } = useUncompletedReports(); const [workers, setWorkers] = useState([]); const [selectedWorker, setSelectedWorker] = useState(""); + // 加载维修工人菜单 useEffect(() => { fetch("/api/workers") .then((res) => res.json())