mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 18:54:09 +00:00
perf: 数据集刷新导致页面抖动
This commit is contained in:
@@ -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;
|
||||||
|
Reference in New Issue
Block a user