Skip to content

Commit

Permalink
chore: changing number upon change of page with state update
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Feb 19, 2024
1 parent 3e85b46 commit ed69a88
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/context/useGetTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Actions, ExplorerContextState, Routes } from "../types"
import { sanitizeTransferData } from "../utils/Helpers"

export function useGetTransferData(routes: Routes, dispatcher: React.Dispatch<Actions>, state: ExplorerContextState, page: number): void {
const pageToUse = page !== 0 && page !== state.queryParams.page ? page : state.queryParams.page

const fetchTransfers = async (): Promise<void> => {
dispatcher({
type: "loading_transfers",
})

const pageToUse = page !== 0 && page !== state.queryParams.page ? page : state.queryParams.page

try {
const transfers = await routes.transfers(`${pageToUse}`, `${state.queryParams.limit}`)
const sanitizedTransfers = sanitizeTransferData(transfers)
Expand All @@ -33,4 +33,16 @@ export function useGetTransferData(routes: Routes, dispatcher: React.Dispatch<Ac
useEffect(() => {
void fetchTransfers()
}, [state.queryParams])

useEffect(() => {
if (pageToUse !== state.queryParams.page) {
dispatcher({
type: "set_query_params",
payload: {
page: pageToUse,
limit: state.queryParams.limit,
},
})
}
}, [page])
}

0 comments on commit ed69a88

Please sign in to comment.