Skip to content

Commit

Permalink
Merge pull request #6 from erich2s:fix-useSWR-usage
Browse files Browse the repository at this point in the history
Fix-useSWR-usage
  • Loading branch information
erich2s authored Oct 8, 2023
2 parents 6410f9f + 57f8255 commit 716c9cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/components/admin/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions src/context/ReportDetailsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function ReportDetailsProvider({
const { mutate } = useUncompletedReports();
const [workers, setWorkers] = useState<worker[]>([]);
const [selectedWorker, setSelectedWorker] = useState<string>("");
// 加载维修工人菜单
useEffect(() => {
fetch("/api/workers")
.then((res) => res.json())
Expand Down

0 comments on commit 716c9cd

Please sign in to comment.