-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add safe txs pagination to prevent the page to become unresponsive if there are many txs.
- Loading branch information
1 parent
e943956
commit fd742f3
Showing
4 changed files
with
131 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useState, useMemo, useCallback } from 'react'; | ||
|
||
interface PaginationResult<T> { | ||
paginatedData: T[]; | ||
hasMore: boolean; | ||
fetchMoreData: () => void; | ||
} | ||
|
||
export function useInMemoryPagination<T>(data: T[], itemsPerPage: number): PaginationResult<T> { | ||
const [displayedItems, setDisplayedItems] = useState(itemsPerPage); | ||
|
||
const paginatedData = useMemo(() => { | ||
// Return all data up to the current number of displayed items | ||
return data.slice(0, displayedItems); | ||
}, [data, displayedItems]); | ||
|
||
const hasMore = useMemo(() => { | ||
return displayedItems < data.length; | ||
}, [data.length, displayedItems]); | ||
|
||
const fetchMoreData = useCallback(() => { | ||
setDisplayedItems((prevItems) => Math.min(prevItems + itemsPerPage, data.length)); | ||
}, [itemsPerPage, data.length]); | ||
|
||
return { paginatedData, hasMore, fetchMoreData }; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.