/
githubmirror
/
Open-Assistant
Обзор
Документация
Войти
/
githubmirror
/
Open-Assistant
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/components/DataTable/useCursorPagination.ts
46 строк
1 KB
notmd
Admin message list (#2057)
14 мар 2023, 20:03
Не верифицирован
14 мар 2023, 20:03
389675d
Код
Авторство
О чём код?
import { useCallback, useState } from "react"; export type CursorPaginationState = { /** * The user's `display_name` used for pagination. */ cursor: string; /** * The pagination direction. */ direction: "forward" | "back"; }; export const useCursorPagination = () => { const [pagination, setPagination] = useState<CursorPaginationState>({ cursor: "", direction: "forward" }); const toPreviousPage = useCallback( (data: undefined | { prev?: string; next?: string }) => { setPagination({ cursor: data?.prev || "", direction: "back", }); }, [setPagination] ); const toNextPage = useCallback( (data: undefined | { prev?: string; next?: string }) => { setPagination({ cursor: data?.next || "", direction: "forward", }); }, [setPagination] ); const resetCursor = useCallback(() => setPagination((old) => ({ ...old, cursor: "" })), []); return { pagination, toNextPage, toPreviousPage, resetCursor, }; };