@@ -4,7 +4,7 @@ import isEqual from 'lodash/isEqual';
4
4
5
5
import { removeEmpty } from '../../util' ;
6
6
import { FilterPayload , RaRecord , SortPayload } from '../../types' ;
7
- import { ResourceContextValue , useResourceContext } from '../../core' ;
7
+ import { useResourceContext } from '../../core' ;
8
8
import usePaginationState from '../usePaginationState' ;
9
9
import useSortState from '../useSortState' ;
10
10
import { useRecordSelection } from './useRecordSelection' ;
@@ -92,12 +92,45 @@ export const useList = <RecordType extends RaRecord = any, ErrorType = Error>(
92
92
total : data ? data . length : undefined ,
93
93
} ) ) ;
94
94
95
+ // Store pagination states for each storeKey
96
+ const storeKeyPaginationRef = useRef < {
97
+ [ key : string ] : { page : number ; perPage : number } ;
98
+ } > ( { } ) ;
99
+
95
100
// pagination logic
96
101
const { page, setPage, perPage, setPerPage } = usePaginationState ( {
97
102
page : initialPage ,
98
103
perPage : initialPerPage ,
99
104
} ) ;
100
105
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
+
101
134
// sort logic
102
135
const { sort, setSort : setSortState } = useSortState ( initialSort ) ;
103
136
const setSort = useCallback (
0 commit comments