@@ -4,7 +4,7 @@ import isEqual from 'lodash/isEqual';
44
55import { removeEmpty } from '../../util' ;
66import { FilterPayload , RaRecord , SortPayload } from '../../types' ;
7- import { ResourceContextValue , useResourceContext } from '../../core' ;
7+ import { useResourceContext } from '../../core' ;
88import usePaginationState from '../usePaginationState' ;
99import useSortState from '../useSortState' ;
1010import { useRecordSelection } from './useRecordSelection' ;
@@ -92,12 +92,45 @@ export const useList = <RecordType extends RaRecord = any, ErrorType = Error>(
9292 total : data ? data . length : undefined ,
9393 } ) ) ;
9494
95+ // Store pagination states for each storeKey
96+ const storeKeyPaginationRef = useRef < {
97+ [ key : string ] : { page : number ; perPage : number } ;
98+ } > ( { } ) ;
99+
95100 // pagination logic
96101 const { page, setPage, perPage, setPerPage } = usePaginationState ( {
97102 page : initialPage ,
98103 perPage : initialPerPage ,
99104 } ) ;
100105
106+ useEffect ( ( ) => {
107+ if ( ! resource ) return ;
108+ // Check if storeKey exists in the pagination store
109+ const currentPagination = storeKeyPaginationRef . current [ resource ] ;
110+ if ( currentPagination ) {
111+ // Restore existing pagination state for the storeKey
112+ if (
113+ page !== currentPagination . page ||
114+ perPage !== currentPagination . perPage
115+ ) {
116+ setPage ( currentPagination . page ) ;
117+ setPerPage ( currentPagination . perPage ) ;
118+ }
119+ } else {
120+ setPage ( initialPage ) ;
121+ setPerPage ( initialPerPage ) ;
122+ }
123+ storeKeyPaginationRef . current [ resource ] = { page, perPage } ;
124+ } , [
125+ resource ,
126+ setPage ,
127+ setPerPage ,
128+ initialPage ,
129+ initialPerPage ,
130+ page ,
131+ perPage ,
132+ ] ) ;
133+
101134 // sort logic
102135 const { sort, setSort : setSortState } = useSortState ( initialSort ) ;
103136 const setSort = useCallback (
0 commit comments