Skip to content

Commit

Permalink
refactor(hooks): modify to slow to show, quick to hide
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Davis <[email protected]>
  • Loading branch information
steveoh and stdavis committed Nov 20, 2024
1 parent 41f4cc3 commit 4ad3dd2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/utilities/src/hooks/useViewLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ export default function useViewLoading(

view.when(() => {
view.watch('updating', (updating: boolean) => {
if (timeoutId) {
if (updating && timeoutId) {
return;
}

if (updating) {
setIsLoading(true);
if (!updating) {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}
setIsLoading(false);
} else {
timeoutId = setTimeout(() => {
setIsLoading(false);
setIsLoading(true);
timeoutId = null;
}, debounceDuration);
}
Expand Down

0 comments on commit 4ad3dd2

Please sign in to comment.