Skip to content

Commit

Permalink
fix: refresh-animation as a separate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Apr 11, 2024
1 parent fbbe0a2 commit 627fdf2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/components/landing-page/use-refresh-animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect, useState } from "react";

type TUseRefreshAnimationOptions = {
reloadProductionList: boolean;
};

export const useRefreshAnimation = ({
reloadProductionList,
}: TUseRefreshAnimationOptions) => {
const [showRefreshing, setShowRefreshing] = useState(true);

useEffect(() => {
let timeout: number | null = null;

if (showRefreshing) {
timeout = window.setTimeout(() => {
setShowRefreshing(false);
}, 1500);
}

return () => {
if (timeout !== null) {
window.clearTimeout(timeout);
}
};
}, [showRefreshing]);

useEffect(() => {
if (reloadProductionList) {
setShowRefreshing(true);
}
}, [reloadProductionList]);

return showRefreshing;
};

0 comments on commit 627fdf2

Please sign in to comment.