Commit a0832af1 by archer

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

parent 677e6141
......@@ -17,13 +17,10 @@ export const usePagination = <T = any,>({
const { toast } = useToast();
const [pageNum, setPageNum] = useState(1);
const [total, setTotal] = useState(0);
const [data, setData] = useState<T[]>([]);
const maxPage = useMemo(() => Math.ceil(total / pageSize), [pageSize, total]);
const {
mutate,
data = [],
isLoading
} = useMutation({
const { mutate, isLoading } = useMutation({
mutationFn: async (num: number = pageNum) => {
try {
const res: PagingData<T> = await api({
......@@ -33,7 +30,7 @@ export const usePagination = <T = any,>({
});
setPageNum(num);
setTotal(res.total);
return res.data;
setData(res.data);
} catch (error: any) {
toast({
title: error?.message || '获取数据异常',
......@@ -43,7 +40,6 @@ export const usePagination = <T = any,>({
}
}
});
useQuery(['init'], () => {
mutate(1);
return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment