This commit is contained in:
Rizky 2024-02-07 21:28:48 +07:00
parent 77075096e6
commit 447b71576d
1 changed files with 13 additions and 5 deletions

View File

@ -17,7 +17,7 @@ export const FieldNumUnit: FC<{
icon, icon,
value, value,
label, label,
update, update: _update,
unit, unit,
hideUnit, hideUnit,
width, width,
@ -35,6 +35,16 @@ export const FieldNumUnit: FC<{
timeout: null as any, timeout: null as any,
}); });
const update: typeof _update = useCallback(
(...arg) => {
clearTimeout(local.timeout);
local.timeout = setTimeout(() => {
_update(...arg);
}, 100);
},
[_update]
);
const parseVal = useCallback(() => { const parseVal = useCallback(() => {
let val = ""; let val = "";
let unt = ""; let unt = "";
@ -83,12 +93,10 @@ export const FieldNumUnit: FC<{
local.val = Math.max(0, local.val); local.val = Math.max(0, local.val);
} }
local.val_str = local.val + "";
local.render(); local.render();
clearTimeout(local.timeout); update(local.val + local.unit);
local.timeout = setTimeout(() => {
update(local.val + local.unit);
}, 300);
} }
}; };