nandorojo / swr-react-native

React Native/React Navigation compatibility for Vercel's useSWR hook. 🐮

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initial Focus causes double requests when loading app (in web)

Jackman3005 opened this issue · comments

I found this code to not be true for us:

const focusCount = useRef(
  Platform.select({
    // react-navigation fire a focus event on the initial mount, but not on web
    web: 1,
    default: 0,
  })
)

We are using:

"@react-navigation/native": "^6.0.4",
"@react-navigation/stack": "^6.2.1",

This causes our initial load of the page on web to perform duplicate requests for each SWR hook.

I have confirmed that the duplicate request is due to the onFocus listener being called immediately on page load. I searched through react-navigation issues and could not identify anything that specifically spoke to this change being made (to fire a focus even on the initial mount on web), although there were some around re-ordering focus and blur events that could have caused this change.

At the very least, I am hoping this setting can become configurable, so we can continue to use the library. In the meantime I think we will have to fork.

Has anyone else had this issue?