Skip to content

Commit a88f1b9

Browse files
Amr LabibAmr Labib
authored andcommitted
add default fallback empty object to all hooks
1 parent 3c24f5e commit a88f1b9

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/useStopwatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState, useCallback } from 'react';
22
import { Time } from './utils';
33
import { useInterval } from './hooks';
44

5-
export default function useStopwatch({ autoStart, offsetTimestamp }) {
5+
export default function useStopwatch({ autoStart, offsetTimestamp } = {}) {
66
const [passedSeconds, setPassedSeconds] = useState(Time.getSecondsFromExpiry(offsetTimestamp, true) || 0);
77
const [prevTime, setPrevTime] = useState(new Date());
88
const [seconds, setSeconds] = useState(passedSeconds + Time.getSecondsFromPrevTime(prevTime || 0, true));

src/useTime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState } from 'react';
22
import { Time } from './utils';
33
import { useInterval } from './hooks';
44

5-
export default function useTime({ format }) {
5+
export default function useTime({ format } = {}) {
66
const [seconds, setSeconds] = useState(Time.getSecondsFromTimeNow());
77

88
useInterval(() => {

src/useTimer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getDelayFromExpiryTimestamp(expiryTimestamp) {
1313
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
1414
}
1515

16-
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart = true }) {
16+
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart = true } = {}) {
1717
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
1818
const [seconds, setSeconds] = useState(Time.getSecondsFromExpiry(expiryTimestamp));
1919
const [isRunning, setIsRunning] = useState(autoStart);

0 commit comments

Comments
 (0)