perf: 数据集刷新导致页面抖动

This commit is contained in:
archer
2023-04-03 00:51:53 +08:00
parent 677e61416d
commit a0832af14b

View File

@@ -17,13 +17,10 @@ export const usePagination = <T = any,>({
const { toast } = useToast(); const { toast } = useToast();
const [pageNum, setPageNum] = useState(1); const [pageNum, setPageNum] = useState(1);
const [total, setTotal] = useState(0); const [total, setTotal] = useState(0);
const [data, setData] = useState<T[]>([]);
const maxPage = useMemo(() => Math.ceil(total / pageSize), [pageSize, total]); const maxPage = useMemo(() => Math.ceil(total / pageSize), [pageSize, total]);
const { const { mutate, isLoading } = useMutation({
mutate,
data = [],
isLoading
} = useMutation({
mutationFn: async (num: number = pageNum) => { mutationFn: async (num: number = pageNum) => {
try { try {
const res: PagingData<T> = await api({ const res: PagingData<T> = await api({
@@ -33,7 +30,7 @@ export const usePagination = <T = any,>({
}); });
setPageNum(num); setPageNum(num);
setTotal(res.total); setTotal(res.total);
return res.data; setData(res.data);
} catch (error: any) { } catch (error: any) {
toast({ toast({
title: error?.message || '获取数据异常', title: error?.message || '获取数据异常',
@@ -43,7 +40,6 @@ export const usePagination = <T = any,>({
} }
} }
}); });
useQuery(['init'], () => { useQuery(['init'], () => {
mutate(1); mutate(1);
return null; return null;