Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-filename-extension": 0,
"no-unused-expressions": [ 2,{
"allowShortCircuit": true,
}],
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ build
!.eslintrc
yarn-error.log
dev-dist
readme-images

*.js
!dist/index.js
Expand Down
36 changes: 21 additions & 15 deletions app/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useTimer } from '../src/index';


function MyTimer({ expiryTimestamp }) {
const {
seconds,
Expand All @@ -10,36 +11,41 @@ function MyTimer({ expiryTimestamp }) {
start,
pause,
resume,
restart
restart,
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });


return (
<div style={{textAlign: 'center'}}>
<div style={{ textAlign: 'center' }}>
<h1>react-timer-hook </h1>
<p>Timer Demo</p>
<div style={{fontSize: '100px'}}>
<div style={{ fontSize: '100px' }}>
<span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
</div>
<button onClick={start}>Start</button>
<button onClick={pause}>Pause</button>
<button onClick={resume}>Resume</button>
<button onClick={() => {
// Restarts to 5 minutes timer
var t = new Date();
t.setSeconds(t.getSeconds() + 300);
restart(t)
}}>restart</button>
<button type="button" onClick={start}>Start</button>
<button type="button" onClick={pause}>Pause</button>
<button type="button" onClick={resume}>Resume</button>
<button
type="button"
onClick={() => {
// Restarts to 5 minutes timer
const time = new Date();
time.setSeconds(time.getSeconds() + 300);
restart(time);
}}
>
Restart
</button>
</div>
);
}

export default function App() {
var t = new Date();
t.setSeconds(t.getSeconds() + 600); // 10 minutes timer
const time = new Date();
time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
return (
<div>
<MyTimer expiryTimestamp={t} />
<MyTimer expiryTimestamp={time} />
</div>
);
}
Binary file removed readme-images/useStopwatch.gif
Binary file not shown.
Binary file removed readme-images/useTime.gif
Binary file not shown.
Binary file removed readme-images/useTimer.gif
Binary file not shown.
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ function MyTimer({ expiryTimestamp }) {
<button onClick={resume}>Resume</button>
<button onClick={() => {
// Restarts to 5 minutes timer
var t = new Date();
t.setSeconds(t.getSeconds() + 300);
restart(t)
}}>restart</button>
const time = new Date();
time.setSeconds(time.getSeconds() + 300);
restart(time)
}}>Restart</button>
</div>
);
}

export default function App() {
var t = new Date();
t.setSeconds(t.getSeconds() + 600); // 10 minutes timer
const time = new Date();
time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
return (
<div>
<MyTimer expiryTimestamp={t} />
<MyTimer expiryTimestamp={time} />
</div>
);
}
Expand Down