Skip to content

Commit 2a9b8d5

Browse files
committed
docs: update react native focus code
1 parent 617c758 commit 2a9b8d5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/src/pages/guides/window-focus-refetching.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,19 @@ focusManager.setEventListener(onWindowFocus) // Boom!
6464
Instead of event listeners on `window`, React Native provides focus information through the [`AppState` module](https://reactnative.dev/docs/appstate#app-states). You can use the `AppState` "change" event to trigger an update when the app state changes to "active":
6565

6666
```js
67-
import { focusManager } from 'react-query'
6867
import { AppState } from 'react-native'
68+
import { focusManager } from 'react-query'
6969

70-
focusManager.setEventListener(handleFocus => {
70+
focusManager.setEventListener(setFocus => {
7171
const handleAppStateChange = appState => {
72-
if (appState === 'active') {
73-
handleFocus()
74-
}
72+
setFocus(appState === 'active')
7573
}
74+
7675
AppState.addEventListener('change', handleAppStateChange)
77-
return () => AppState.removeEventListener('change', handleAppStateChange)
76+
77+
return () => {
78+
AppState.removeEventListener('change', handleAppStateChange)
79+
}
7880
})
7981
```
8082

0 commit comments

Comments
 (0)