Skip to content

Commit

Permalink
Make countdown onDown return remaining time
Browse files Browse the repository at this point in the history
  • Loading branch information
imbhargav5 committed Dec 5, 2019
1 parent f130c10 commit cfbe478
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/countdown/src/useCountdown.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useState } from 'react';
import { useInterval } from 'shared/useInterval';
import { useState } from "react";
import { useInterval } from "shared/useInterval";

type CountdownOptions = {
interval?: number,
onDown?: Function,
onEnd?: Function,
interval?: number;
onDown?: Function;
onEnd?: Function;
};

const useCountdown = (
endTime: Date,
endTime: Date,
{ interval = 1000, onDown, onEnd }: CountdownOptions = {}
): number => {
const [time, setTime] = useState<Date>(() => new Date());
Expand All @@ -24,16 +24,16 @@ const useCountdown = (
if (newTime > endTime) {
if (onEnd) {
onEnd(newTime);
}
}
setTime(endTime);
return;
}
}

if (onDown) {
onDown(newTime);
onDown(restTime, newTime);
}
setTime(newTime);
}
}
};

export default useCountdown;

0 comments on commit cfbe478

Please sign in to comment.