Skip to content

Commit

Permalink
fix: typeof temporary dead zone (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
hchlq authored May 16, 2022
1 parent 1c411e0 commit e8a40ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/hooks/src/useRequest/src/utils/isOnline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isUndef } from '../../../utils';
import canUseDom from '../../../utils/canUseDom';

export default function isOnline(): boolean {
if (canUseDom() && !isUndef(navigator.onLine)) {
if (canUseDom() && typeof navigator.onLine !== 'undefined') {
return navigator.onLine;
}
return true;
Expand Down
4 changes: 1 addition & 3 deletions packages/hooks/src/utils/canUseDom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isUndef } from './index';

export default function canUseDom() {
return !!(!isUndef(window) && window.document && window.document.createElement);
return !!(typeof window !== 'undefined' && window.document && window.document.createElement);
}
8 changes: 5 additions & 3 deletions packages/hooks/src/utils/isBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isUndef } from './index';

const isBrowser = !!(!isUndef(window) && window.document && window.document.createElement);
const isBrowser = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
);

export default isBrowser;

0 comments on commit e8a40ff

Please sign in to comment.