mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-23 00:06:15 -04:00
fix(emoji-picker): debounced search input (#1181)
* fix(Emoji picker): fix lags Fix #1176 using debounced ref * chore: fix strange corepack message Fix corepack claiming strange thing : UsageError: This project is configured to use yarn because /home/runner/work/it-tools/it-tools/package.json has a "packageManager" field
This commit is contained in:
parent
b430baef40
commit
76a19d218d
3 changed files with 25 additions and 2 deletions
21
src/composable/debouncedref.ts
Normal file
21
src/composable/debouncedref.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
|
||||
const state = ref(initialValue);
|
||||
const debouncedRef = customRef((track, trigger) => ({
|
||||
get() {
|
||||
track();
|
||||
return state.value;
|
||||
},
|
||||
set: _.debounce(
|
||||
(value) => {
|
||||
state.value = value;
|
||||
trigger();
|
||||
},
|
||||
delay,
|
||||
{ leading: immediate },
|
||||
),
|
||||
}));
|
||||
return debouncedRef;
|
||||
}
|
||||
export default useDebouncedRef;
|
Loading…
Add table
Add a link
Reference in a new issue