diff --git a/src/lib/useGetAbstractParams.ts b/src/lib/useGetAbstractParams.ts index ba004b8b1..b34901e19 100644 --- a/src/lib/useGetAbstractParams.ts +++ b/src/lib/useGetAbstractParams.ts @@ -1,3 +1,4 @@ +import { AppState, useStore } from '@/store'; import { useCallback, useEffect, useRef, useState } from 'react'; /** @@ -5,12 +6,17 @@ import { useCallback, useEffect, useRef, useState } from 'react'; */ export const useGetAbstractParams = (id: string) => { const [start, setStart] = useState(0); + const pageSize = useStore((state: AppState) => state.numPerPage); + const prev = useRef(); useEffect(() => { prev.current = id; }); // reset start if the previous bibcode is different than the current - const getParams = useCallback(() => ({ bibcode: id, start: prev.current === id ? start : 0 }), [id, start]); + const getParams = useCallback( + () => ({ bibcode: id, start: prev.current === id ? start * pageSize : 0 }), + [id, start, pageSize], + ); return { getParams, onPageChange: setStart }; };