Skip to content

Commit

Permalink
refactor: extract initial state to function
Browse files Browse the repository at this point in the history
  • Loading branch information
beawar committed Aug 12, 2024
1 parent 87d288e commit 7a59ca7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/boot/loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ export const LoaderFailureModal = ({
);
};

function calcInitialCounter(sessionLifetime: number): number {
const oneMinute = 60 * 1000;
return Math.ceil(Math.min(sessionLifetime, oneMinute) / 1000);
}

const ExpiringSessionDynamicLabel = ({
sessionLifetime
}: {
sessionLifetime: number;
}): React.JSX.Element => {
const oneMinute = 60 * 1000;
const initialCounter = Math.ceil(Math.min(sessionLifetime, oneMinute) / 1000);
const [t] = useTranslation();
const [count, setCount] = useState(initialCounter);
const [count, setCount] = useState(calcInitialCounter(sessionLifetime));

useEffect(() => {
const interval = setInterval(() => {
Expand All @@ -82,7 +85,7 @@ const ExpiringSessionDynamicLabel = ({
return (): void => {
clearInterval(interval);
};
}, [initialCounter]);
}, []);

return (
<>
Expand Down

0 comments on commit 7a59ca7

Please sign in to comment.