{"version":3,"file":"useNetworkConnectionState.mjs","names":[],"sources":["../../../../../src/components/Chat/hooks/useNetworkConnectionState.ts"],"sourcesContent":["import type { NetworkConnectionState } from 'stream-chat';\n\nimport { useChatContext } from '../../../context/ChatContext';\nimport { useStateStore } from '../../../store';\n\nconst identity = (state: NetworkConnectionState) => state;\n\n/**\n * The device's network status, as reported by the platform listener registered on\n * `client.networkConnection`.\n *\n * Not the WebSocket status of {@link useWSConnectionState}: a socket can die on a working network,\n * and a device can drop before the socket notices. `isOnline` is `undefined` while unknown (no\n * reporter installed, or none has reported yet), so test `isOnline === false`, not `!isOnline`.\n *\n * Must run under `ChatProvider`, e.g. from a child of `<Chat>`.\n */\nexport const useNetworkConnectionState = (): NetworkConnectionState | undefined => {\n  const { client } = useChatContext();\n  return useStateStore(client?.networkConnection.state, identity);\n};\n\n/**\n * {@link useNetworkConnectionState} narrowed to what a component reads, so it re-renders only when\n * that changes. The selector must return a flat object or tuple, which is shallow-compared.\n *\n * @example\n * ```tsx\n * const isOffline = useNetworkConnectionStateSelector(\n *   ({ isOnline }) => ({ isOffline: isOnline === false }),\n * )?.isOffline;\n * ```\n */\nexport const useNetworkConnectionStateSelector = <\n  O extends Readonly<Record<string, unknown> | Readonly<unknown[]>>,\n>(\n  selector: (state: NetworkConnectionState) => O,\n): O | undefined => {\n  const { client } = useChatContext();\n  return useStateStore(client?.networkConnection.state, selector);\n};\n"],"mappings":";;;AAKA,IAAM,YAAY,UAAkC;;;;;;;;;;;AAYpD,IAAa,kCAAsE;CACjF,MAAM,EAAE,WAAW,eAAe;CAClC,OAAO,cAAc,QAAQ,kBAAkB,OAAO,QAAQ;AAChE;;;;;;;;;;;;AAaA,IAAa,qCAGX,aACkB;CAClB,MAAM,EAAE,WAAW,eAAe;CAClC,OAAO,cAAc,QAAQ,kBAAkB,OAAO,QAAQ;AAChE"}