Skip to content

Commit

Permalink
Use refs current value
Browse files Browse the repository at this point in the history
  • Loading branch information
Loeffeldude committed Dec 28, 2024
1 parent c8bec94 commit f704606
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/react/src/WhenVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const WhenVisible = ({ children, data, params, buffer, as, always, fallback }: W
fallback = fallback ?? null

const [loaded, setLoaded] = useState(false)
const fetchedOnce = useRef<boolean>(false)
const fetchedOnceRef = useRef<boolean>(false)
const fetchingRef = useRef<boolean>(false)
const ref = useRef<HTMLDivElement>(null)

Expand Down Expand Up @@ -46,15 +46,15 @@ const WhenVisible = ({ children, data, params, buffer, as, always, fallback }: W
return
}

if (!always && fetchedOnce) {
if (!always && fetchedOnceRef.current) {
observer.disconnect()
}

if (fetchingRef.current) {
return
}

fetchedOnce.current = true
fetchedOnceRef.current = true
fetchingRef.current = true

const reloadParams = getReloadParams()
Expand Down

0 comments on commit f704606

Please sign in to comment.