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() {
780
780
return [ state , ref ] ;
781
781
}
782
782
783
- export function useNetworkState ( ) {
784
- const connection =
783
+ const getConnection = ( ) => {
784
+ return (
785
785
navigator ?. connection ||
786
786
navigator ?. mozConnection ||
787
- navigator ?. webkitConnection ;
787
+ navigator ?. webkitConnection
788
+ ) ;
789
+ } ;
788
790
791
+ export function useNetworkState ( ) {
789
792
const cache = React . useRef ( { } ) ;
790
793
791
794
const subscribe = React . useCallback ( ( callback ) => {
792
795
window . addEventListener ( "online" , callback , { passive : true } ) ;
793
796
window . addEventListener ( "offline" , callback , { passive : true } ) ;
794
797
798
+ const connection = getConnection ( ) ;
799
+
795
800
if ( connection ) {
796
801
connection . addEventListener ( "change" , callback , { passive : true } ) ;
797
802
}
@@ -808,6 +813,7 @@ export function useNetworkState() {
808
813
809
814
const getSnapshot = ( ) => {
810
815
const online = navigator . onLine ;
816
+ const connection = getConnection ( ) ;
811
817
812
818
const nextState = {
813
819
online,
You can’t perform that action at this time.
0 commit comments