Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/usePagination][taier-ui]fix pagination get incorrect #809

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions taier-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ interface IPagination {

export const usePagination = ({
current: initialCurrent = 1,
pageSize: initalPageSize = 20,
pageSize: initialPageSize = 20,
total: initialTotal = 0,
}: IPagination) => {
const [current, setCurrent] = useState(initialCurrent);
const [pageSize, setPageSize] = useState(initalPageSize);
const [pageSize, setPageSize] = useState(initialPageSize);
const [total, setTotal] = useState(initialTotal);

// ensure get the lastest value inside async function
const pageInfoRef = useRef({ current, pageSize, total });
useEffect(() => {
pageInfoRef.current = { current, pageSize, total };
});

const setPagination = ({
current: c,
pageSize: p,
Expand All @@ -59,7 +53,12 @@ export const usePagination = ({
}
};

return { ...pageInfoRef.current, setPagination };
return {
current,
pageSize,
total,
setPagination,
};
};

export function useConstant<T>(val: T) {
Expand Down