File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -780,18 +780,23 @@ export function useMouse() {
780780 return [ state , ref ] ;
781781}
782782
783- export function useNetworkState ( ) {
784- const connection =
783+ const getConnection = ( ) => {
784+ return (
785785 navigator ?. connection ||
786786 navigator ?. mozConnection ||
787- navigator ?. webkitConnection ;
787+ navigator ?. webkitConnection
788+ ) ;
789+ } ;
788790
791+ export function useNetworkState ( ) {
789792 const cache = React . useRef ( { } ) ;
790793
791794 const subscribe = React . useCallback ( ( callback ) => {
792795 window . addEventListener ( "online" , callback , { passive : true } ) ;
793796 window . addEventListener ( "offline" , callback , { passive : true } ) ;
794797
798+ const connection = getConnection ( ) ;
799+
795800 if ( connection ) {
796801 connection . addEventListener ( "change" , callback , { passive : true } ) ;
797802 }
@@ -808,6 +813,7 @@ export function useNetworkState() {
808813
809814 const getSnapshot = ( ) => {
810815 const online = navigator . onLine ;
816+ const connection = getConnection ( ) ;
811817
812818 const nextState = {
813819 online,
You can’t perform that action at this time.
0 commit comments