@@ -6,6 +6,8 @@ import { checkEnabledExchanges } from '../../actions/SettingsActions'
6
6
import { SCROLL_INDICATOR_INSET_FIX } from '../../constants/constantSettings'
7
7
import { useAbortable } from '../../hooks/useAbortable'
8
8
import { useHandler } from '../../hooks/useHandler'
9
+ import { useMount } from '../../hooks/useMount'
10
+ import { useUnmount } from '../../hooks/useUnmount'
9
11
import { lstrings } from '../../locales/strings'
10
12
import { getCoingeckoFiat } from '../../selectors/SettingsSelectors'
11
13
import { FooterRender } from '../../state/SceneFooterState'
@@ -142,24 +144,27 @@ const CoinRankingComponent = (props: Props) => {
142
144
setFooterHeight ( height )
143
145
} )
144
146
145
- React . useEffect ( ( ) => {
146
- if ( lastSceneFiat !== coingeckoFiat ) {
147
+ useMount ( ( ) => {
148
+ console . debug ( 'useMount' )
149
+ if ( lastSceneFiat == null ) {
150
+ lastSceneFiat = coingeckoFiat
151
+ } else if ( lastSceneFiat !== coingeckoFiat ) {
147
152
// Clear cache if we changed the fiat while outside of this scene
148
153
debugLog ( LOG_COINRANK , 'Clearing coinRankingDatas cache' )
149
154
coinRanking . coinRankingDatas = [ ]
150
155
lastStartIndex . current = 1
151
156
setDataSize ( 0 )
152
157
setRequestDataSize ( QUERY_PAGE_SIZE )
153
158
}
159
+ } )
154
160
155
- return ( ) => {
156
- mounted . current = false
161
+ useUnmount ( ( ) => {
162
+ console . debug ( 'useUnmount' )
163
+ mounted . current = false
157
164
158
- // Queries should update this, but just in case:
159
- lastSceneFiat = coingeckoFiat
160
- }
161
- // eslint-disable-next-line react-hooks/exhaustive-deps
162
- } , [ ] )
165
+ // Queries should update this, but just in case:
166
+ lastSceneFiat = coingeckoFiat
167
+ } )
163
168
164
169
React . useEffect ( ( ) => {
165
170
return navigation . addListener ( 'focus' , ( ) => {
@@ -170,7 +175,7 @@ const CoinRankingComponent = (props: Props) => {
170
175
// Start querying starting from either the last fetched index (scrolling) or
171
176
// the first index (initial load/timed refresh)
172
177
const queryLoop = useAbortable ( maybeAbort => async ( startIndex : number ) => {
173
- debugLog ( LOG_COINRANK , `queryLoop(start: ${ startIndex } )` )
178
+ debugLog ( LOG_COINRANK , `queryLoop(start: ${ startIndex } , size: ${ requestDataSize } )` )
174
179
175
180
try {
176
181
// Catch up to the total required items. Always fetch if requesting the
@@ -228,7 +233,8 @@ const CoinRankingComponent = (props: Props) => {
228
233
}
229
234
230
235
return ( ) => {
231
- // Reset related query state when this effect is unmounted (coingeckoFiat
236
+ console . debug ( 'queryLoop cleanup, mounted.current: ' , mounted . current )
237
+ // Reset related query state when this effect is cleaned up (coingeckoFiat
232
238
// changed), but the scene is still mounted:
233
239
if ( mounted . current ) {
234
240
debugLog ( LOG_COINRANK , `Clearing coinRankingDatas cache for new fiat: ${ coingeckoFiat } ` )
@@ -241,7 +247,6 @@ const CoinRankingComponent = (props: Props) => {
241
247
setRequestDataSize ( QUERY_PAGE_SIZE )
242
248
}
243
249
}
244
- // eslint-disable-next-line react-hooks/exhaustive-deps
245
250
} , [ coingeckoFiat /* reset subscription on fiat change */ , queryLoop ] )
246
251
247
252
const listData : number [ ] = React . useMemo ( ( ) => {
0 commit comments