@@ -3,7 +3,7 @@ import get from 'lodash/get';
3
3
import isEqual from 'lodash/isEqual' ;
4
4
import { removeEmpty } from '../../util' ;
5
5
import { FilterPayload , RaRecord , SortPayload } from '../../types' ;
6
- import { ResourceContextValue , useResourceContext } from '../../core' ;
6
+ import { useResourceContext } from '../../core' ;
7
7
import usePaginationState from '../usePaginationState' ;
8
8
import useSortState from '../useSortState' ;
9
9
import { useRecordSelection } from './useRecordSelection' ;
@@ -91,12 +91,45 @@ export const useList = <RecordType extends RaRecord = any>(
91
91
total : data ? data . length : undefined ,
92
92
} ) ) ;
93
93
94
+ // Store pagination states for each storeKey
95
+ const storeKeyPaginationRef = useRef < {
96
+ [ key : string ] : { page : number ; perPage : number } ;
97
+ } > ( { } ) ;
98
+
94
99
// pagination logic
95
100
const { page, setPage, perPage, setPerPage } = usePaginationState ( {
96
101
page : initialPage ,
97
102
perPage : initialPerPage ,
98
103
} ) ;
99
104
105
+ useEffect ( ( ) => {
106
+ if ( ! resource ) return ;
107
+ // Check if storeKey exists in the pagination store
108
+ const currentPagination = storeKeyPaginationRef . current [ resource ] ;
109
+ if ( currentPagination ) {
110
+ // Restore existing pagination state for the storeKey
111
+ if (
112
+ page !== currentPagination . page ||
113
+ perPage !== currentPagination . perPage
114
+ ) {
115
+ setPage ( currentPagination . page ) ;
116
+ setPerPage ( currentPagination . perPage ) ;
117
+ }
118
+ } else {
119
+ setPage ( initialPage ) ;
120
+ setPerPage ( initialPerPage ) ;
121
+ }
122
+ storeKeyPaginationRef . current [ resource ] = { page, perPage } ;
123
+ } , [
124
+ resource ,
125
+ setPage ,
126
+ setPerPage ,
127
+ initialPage ,
128
+ initialPerPage ,
129
+ page ,
130
+ perPage ,
131
+ ] ) ;
132
+
100
133
// sort logic
101
134
const { sort, setSort : setSortState } = useSortState ( initialSort ) ;
102
135
const setSort = useCallback (
0 commit comments