Skip to content

Commit

Permalink
feat(util-hooks): update useDebouncedActionSequence
Browse files Browse the repository at this point in the history
- reduce delay time
- run the action immediately if it's the first action
  • Loading branch information
runjuu committed Jul 31, 2023
1 parent 73420bc commit 5688f9f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/util-hooks/src/use-debounced-action-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ export type UseDebouncedActionSequenceConfigAddOptions = {
};

export function useDebouncedActionSequence({
delay = 1000,
delay = 600,
onError,
}: UseDebouncedActionSequenceConfig) {
const actionIdRef = React.useRef(0);
const [action, _setAction] = React.useState(NOOP);

React.useEffect(() => {
const timeout = window.setTimeout(action.run, delay);
const timeout = window.setTimeout(
action.run,
actionIdRef.current === 0 ? 0 : delay,
);
return () => window.clearTimeout(timeout);
}, [action]);

Expand Down

0 comments on commit 5688f9f

Please sign in to comment.