Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

984 B
Raw Blame
import { focusManager, onlineManager, QueryClient } from '@tanstack/react-query'
import { AppState } from 'react-native'

import { monitorConnectivity } from '@/lib/connectivity'

onlineManager.setEventListener(monitorConnectivity)

// TanStack's default focus listener needs `window` visibility events, which React Native lacks, so the focus state never
// changed on iOS or Android. App state drives it instead.
focusManager.setEventListener((setFocused) => {
    const subscription = AppState.addEventListener('change', (state) => setFocused(state === 'active'))
    return () => subscription.remove()
})

export const queryClient = new QueryClient({
    defaultOptions: {
        queries: {
            staleTime: 30_000,
            retry: 1,
            // Focus refetch stays opt-in per query. With the 30 s stale time, a default of true would refetch the inbox
            // and chats on every return to the app.
            refetchOnWindowFocus: false,
        },
    },
})