Skip to content

Commit

Permalink
fix: useDebounce 在小程序里使用问题 (alibaba#1472)
Browse files Browse the repository at this point in the history
* fix: useDebounce 在小程序里使用问题

* chore: 优化声明

---------

Co-authored-by: 云泥 <[email protected]>
Co-authored-by: huangcheng <[email protected]>
  • Loading branch information
3 people authored and askwuxue committed Jul 29, 2023
1 parent e0b2505 commit 11f9115
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/hooks/src/useDebounceFn/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from 'lodash-es';
import { debounce } from '../utils/lodash-polyfill';
import { useMemo } from 'react';
import type { DebounceOptions } from '../useDebounce/debounceOptions';
import useLatest from '../useLatest';
Expand Down
17 changes: 17 additions & 0 deletions packages/hooks/src/utils/lodash-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { debounce } from 'lodash-es';

function isNodeOrWeb() {
const freeGlobal =
(typeof global === 'undefined' ? 'undefined' : typeof global) == 'object' &&
global &&
global.Object === Object &&
global;
const freeSelf = typeof self == 'object' && self && self.Object === Object && self;
return freeGlobal || freeSelf;
}

if (!isNodeOrWeb()) {
global.Date = Date;
}

export { debounce };

0 comments on commit 11f9115

Please sign in to comment.