Skip to content

Commit

Permalink
feat: add onPause to useStopwatch #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcastillop committed Apr 6, 2024
1 parent bc00592 commit 9352f16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useCountUp } from "./hooks";
import { useStopwatch } from "./hooks";

const App = () => {
const { current, isPaused, isOver, pause, play, reset, togglePause } =
useCountUp(1, 10, {
onFinish: () => console.log("Counter ended"),
});
useStopwatch();

return (
<div>
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/useInternalStopwatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InternalCounter, StopwatchOptions } from "../interfaces";
export const useInternalStopwatch = (
options: StopwatchOptions
): InternalCounter => {
const { startPaused, separator, onFinish, endTime } = options;
const { startPaused, separator, onFinish, endTime, onPause } = options;
const { days, hours, minutes, seconds } = parseTime(endTime ?? "0:0:0:0");
const [time, setTime] = useState({
days: 0,
Expand Down Expand Up @@ -96,7 +96,10 @@ export const useInternalStopwatch = (
time.minutes * 60 +
time.seconds)
: 0,
pause: () => setPaused(true),
pause: () => {
setPaused(true);
onPause && onPause();
},
play: () => setPaused(false),
reset: () => {
setIsOver(false);
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface BaseCounterOptions {

export interface TimerOptions extends BaseCounterOptions {
separator?: string;
onPause?: () => void;
}

export interface StopwatchOptions extends TimerOptions {
Expand Down

0 comments on commit 9352f16

Please sign in to comment.