Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
176aecf
handle useTimer with single seconds state and create util files for V…
amrlabib Jan 14, 2020
28083dc
fix useTimer expire after resume
amrlabib Jan 14, 2020
8ca3324
update useTime to use only seconds state
amrlabib Jan 14, 2020
4b099c1
use single seconds state in useStopwatch
amrlabib Jan 14, 2020
a9d1ce3
Merge pull request #22 from amrlabib/enhancement/distance
amrlabib Jan 15, 2020
5e51ed4
minor updates in readme file
amrlabib Jan 15, 2020
9bf1afa
minor changes in App.js
amrlabib Jan 15, 2020
25ed228
remove readme-images folder
amrlabib Jan 15, 2020
456b2c6
use const time instead of t in readme file and App.js
amrlabib Jan 15, 2020
25dbf1d
Merge pull request #24 from amrlabib/readme-updates
amrlabib Jan 15, 2020
b739db7
v2.0.0 in package.json
amrlabib Jan 15, 2020
0470ae1
Bump acorn from 5.7.3 to 5.7.4
dependabot[bot] Mar 14, 2020
02b5de1
add isRunning state to useTimer
amrlabib Apr 9, 2020
c4555ca
enhancement setIsRunning to false only from clearIntervalRef
amrlabib Apr 9, 2020
c659d7f
add isRunning state to useStopwatch
amrlabib Apr 9, 2020
15d7c32
update readme with isRunning flag
amrlabib Apr 9, 2020
240e1b6
minor enhancement in App.js
amrlabib Apr 9, 2020
1b29b03
minor enhancement isRunning location in code
amrlabib Apr 9, 2020
409a375
minor enhancement
amrlabib Apr 9, 2020
04535eb
Merge pull request #27 from amrlabib/feature/running-state
amrlabib Apr 9, 2020
4ef2090
Merge pull request #25 from amrlabib/dependabot/npm_and_yarn/acorn-5.7.4
amrlabib Apr 9, 2020
8564e11
v2.0.1 in package.json
amrlabib Apr 9, 2020
0acc461
add isRunning in typescript definitions
amrlabib Apr 9, 2020
937932e
v2.0.2 in package.json
amrlabib Apr 9, 2020
dfdf745
Bump websocket-extensions from 0.1.3 to 0.1.4
dependabot[bot] Jun 6, 2020
2db12d1
Bump elliptic from 6.4.1 to 6.5.3
dependabot[bot] Jul 31, 2020
dfa2ac0
Merge pull request #32 from amrlabib/dependabot/npm_and_yarn/websocke…
amrlabib Sep 4, 2020
aab575f
Bump lodash from 4.17.14 to 4.17.20
dependabot[bot] Sep 4, 2020
c006d69
Merge pull request #34 from amrlabib/dependabot/npm_and_yarn/elliptic…
amrlabib Sep 4, 2020
976becf
Merge pull request #36 from amrlabib/dependabot/npm_and_yarn/lodash-4…
amrlabib Sep 4, 2020
fbc00ef
set globalObject in webpack config files to fix SSR
amrlabib Sep 4, 2020
ff8a15e
Merge pull request #37 from amrlabib/fix/ssr
amrlabib Sep 4, 2020
6762b75
v2.0.3 in package.json
amrlabib Sep 4, 2020
c6c2ab8
Bump http-proxy from 1.17.0 to 1.18.1
dependabot[bot] Sep 10, 2020
05652a9
Merge pull request #38 from amrlabib/dependabot/npm_and_yarn/http-pro…
amrlabib Sep 10, 2020
c3e834f
update peer dependencies react dom to support new minor versions
amrlabib Nov 27, 2020
b910485
support millisecond accuracy and minor enhancement
amrlabib Nov 28, 2020
97a830d
Time util calculation seconds ceil
amrlabib Nov 30, 2020
8a36780
useTimer minor code enhancement
amrlabib Nov 30, 2020
017a350
setIsRunning to true in handleExtraMilliSeconds
amrlabib Nov 30, 2020
4946e43
commented milliseconds example in App.js
amrlabib Nov 30, 2020
a8884d0
Merge pull request #40 from amrlabib/millisecond-accuracy
amrlabib Nov 30, 2020
c933ef9
v2.0.4 in package.json
amrlabib Nov 30, 2020
c4b8370
handle less than a second timer inside handleExtraMilliSeconds
amrlabib Nov 30, 2020
e1bcb47
v2.0.5 in package.json
amrlabib Nov 30, 2020
8d802bb
changes for github pages demo
amrlabib Dec 4, 2020
312003e
changes for github pages
amrlabib Dec 4, 2020
0cf6f8f
demo components
amrlabib Dec 4, 2020
1fd3c7d
demo styling
amrlabib Dec 4, 2020
e3474a9
add days in use timer demo
amrlabib Dec 4, 2020
e6df807
demo style changes
amrlabib Dec 5, 2020
a3d04f2
update github pages docs folder
amrlabib Dec 5, 2020
75dab27
add live demo links
amrlabib Dec 5, 2020
5dca44b
demo style updates
amrlabib Dec 5, 2020
81663a5
demo docs build
amrlabib Dec 5, 2020
59057db
more changes in demo
amrlabib Dec 5, 2020
8dc680c
v2.0.6 in package.json
amrlabib Dec 5, 2020
e6fc945
updates for github pages demo
amrlabib Dec 5, 2020
7be5b27
minor change in readme file
amrlabib Dec 5, 2020
6caf188
package.json remove space from version number
amrlabib Dec 5, 2020
dd1a16b
Bump ini from 1.3.5 to 1.3.7
dependabot[bot] Dec 11, 2020
0a7f180
support offset time in useStopwatch
amrlabib Dec 24, 2020
2c22cdd
readme update
amrlabib Dec 24, 2020
bdc0b38
readme update
amrlabib Dec 24, 2020
b19f9a4
Merge pull request #43 from amrlabib/use-stopwatch-offset
amrlabib Dec 24, 2020
1a23b85
Merge pull request #41 from amrlabib/dependabot/npm_and_yarn/ini-1.3.7
amrlabib Dec 24, 2020
80d910a
v2.0.7 in package.json
amrlabib Dec 24, 2020
f7023e5
Bump elliptic from 6.5.3 to 6.5.4
dependabot[bot] Mar 9, 2021
a24d420
Merge pull request #47 from amrlabib/dependabot/npm_and_yarn/elliptic…
amrlabib Apr 10, 2021
24df843
add useInterval and reimplement useTimer in cleaner way
amrlabib Apr 10, 2021
a6986b2
handle pause and start similar to current behaviour
amrlabib Apr 10, 2021
dffecde
consider autoStart in restart function
amrlabib Apr 10, 2021
c7a1cdd
handle useTime using useInterval
amrlabib Apr 10, 2021
0dae45f
add useInterval in useStopwatch
amrlabib Apr 10, 2021
4919d54
handle pause by setting delay to null
amrlabib Apr 10, 2021
87cdd72
useTimer restart minor fix
amrlabib Apr 10, 2021
8dd11b0
handle milliseconds in useTimer after new implementation
amrlabib Apr 13, 2021
f36a879
remove old useTimer
amrlabib Apr 14, 2021
110228b
add autoStart of useTimer in Readme file
amrlabib Apr 14, 2021
f7c6835
Merge pull request #48 from amrlabib/enhancement/use-interval
amrlabib Apr 17, 2021
7f79b31
version 3.0.0 in package.json
amrlabib Apr 17, 2021
03a181c
use timer demo minor update in restart and readme updates
amrlabib Apr 17, 2021
8018222
set autoStart to true by default in both restart and reset
amrlabib Apr 17, 2021
97c0c7c
update typescript definitions
amrlabib Apr 17, 2021
89bbe56
useTimer code enhancements and expiry timestamp validation
amrlabib Apr 17, 2021
f85040b
v3.0.1 in package.json
amrlabib Apr 17, 2021
1daeeb2
update demo
amrlabib Apr 17, 2021
7af8a02
update useTimer to have autoStart set to true by default
amrlabib Apr 17, 2021
802e66c
v3.0.2 in package.json
amrlabib Apr 17, 2021
7bbb7d8
Bump url-parse from 1.4.3 to 1.5.1
dependabot[bot] May 8, 2021
ddb4cfb
Bump lodash from 4.17.20 to 4.17.21
dependabot[bot] May 9, 2021
2d3001d
update peerDependencies versions range
amrlabib May 11, 2021
7d600af
Merge pull request #51 from amrlabib/dependabot/npm_and_yarn/lodash-4…
amrlabib May 11, 2021
e76a865
Merge pull request #50 from amrlabib/dependabot/npm_and_yarn/url-pars…
amrlabib May 11, 2021
d9782d9
Bump hosted-git-info from 2.8.5 to 2.8.9
dependabot[bot] May 11, 2021
cb5e91f
v3.0.3 in package.json
amrlabib May 11, 2021
589a50a
add autoStart in TimerSettings
ydhn May 23, 2021
ca9e27d
Bump dns-packet from 1.3.1 to 1.3.4
dependabot[bot] May 27, 2021
2ad2650
Merge pull request #55 from amrlabib/dependabot/npm_and_yarn/dns-pack…
amrlabib Jun 5, 2021
5c5ba73
Merge pull request #54 from ydhn/master
amrlabib Jun 5, 2021
10ccdcd
Merge pull request #53 from amrlabib/dependabot/npm_and_yarn/hosted-g…
amrlabib Jun 5, 2021
0c648c1
fix useStopwatch
amrlabib Jun 18, 2021
6393aa8
Merge pull request #60 from amrlabib/fix/useStopwatch
amrlabib Jun 18, 2021
bbc8363
update docs file
amrlabib Jun 18, 2021
8d21542
Update index.d.ts
haleo9000 Jul 10, 2021
d7f7e29
Bump tar from 4.4.6 to 4.4.15
dependabot[bot] Aug 4, 2021
9d3b357
Bump path-parse from 1.0.6 to 1.0.7
dependabot[bot] Aug 11, 2021
b188d9e
Merge pull request #63 from amrlabib/dependabot/npm_and_yarn/path-par…
amrlabib Aug 27, 2021
06b01ce
Bump url-parse from 1.5.1 to 1.5.3
dependabot[bot] Aug 27, 2021
59af1c7
Merge pull request #62 from amrlabib/dependabot/npm_and_yarn/tar-4.4.15
amrlabib Aug 27, 2021
aed806d
Merge pull request #64 from amrlabib/dependabot/npm_and_yarn/url-pars…
amrlabib Aug 27, 2021
ca7e18d
Bump minimist from 1.2.0 to 1.2.5
dependabot[bot] Aug 27, 2021
cac86e0
Merge pull request #61 from haleo9000/haleo9000-patch-1
amrlabib Sep 12, 2021
8584992
Merge pull request #66 from amrlabib/dependabot/npm_and_yarn/minimist…
amrlabib Sep 12, 2021
1576f20
update date types
amrlabib Sep 12, 2021
f345d7b
version 3.0.5 in package.json
amrlabib Sep 12, 2021
2b0dbc7
Bump ajv from 6.5.4 to 6.12.6
dependabot[bot] Feb 12, 2022
4d1ab6a
Bump follow-redirects from 1.13.0 to 1.14.8
dependabot[bot] Feb 12, 2022
1165a36
Bump url-parse from 1.5.3 to 1.5.10
dependabot[bot] Feb 26, 2022
a0c8370
Bump minimist from 1.2.5 to 1.2.6
dependabot[bot] Mar 24, 2022
218f68a
remove react-dom from peerDependencies to fix #84 for react native
amrlabib May 6, 2022
899fc0d
Merge pull request #80 from amrlabib/dependabot/npm_and_yarn/minimist…
amrlabib May 6, 2022
82d3a21
Merge pull request #78 from amrlabib/dependabot/npm_and_yarn/url-pars…
amrlabib May 6, 2022
a985d0a
Merge pull request #76 from amrlabib/dependabot/npm_and_yarn/follow-r…
amrlabib May 6, 2022
794c67a
Merge pull request #75 from amrlabib/dependabot/npm_and_yarn/ajv-6.12.6
amrlabib May 6, 2022
588e314
update dev environment code and packages
Apr 30, 2023
99773af
cache hooks callback functions
May 6, 2023
c487027
Merge pull request #95 from amrlabib/cache-functions
amrlabib May 6, 2023
3c24f5e
add totalSeconds in useTimer and useStopwatch
May 6, 2023
a88f1b9
add default fallback empty object to all hooks
May 6, 2023
936dc19
bump version to 3.0.6
May 13, 2023
6cdae9a
Bump json5 from 0.5.1 to 1.0.2
dependabot[bot] May 13, 2023
46aad20
Merge pull request #96 from amrlabib/dependabot/npm_and_yarn/json5-1.0.2
amrlabib May 14, 2023
6f9dfc7
fix: Fix type for time returns; should have a `totalSeconds` property…
kilokeith Jun 21, 2023
f201549
build: update build number
kilokeith Jun 21, 2023
e8e8fef
build: build package on install
kilokeith Jun 22, 2023
84ccd0b
Bump semver from 5.7.1 to 5.7.2
dependabot[bot] Jul 11, 2023
aa90616
Bump word-wrap from 1.2.3 to 1.2.4
dependabot[bot] Jul 18, 2023
87e2ffb
Merge pull request #98 from kilokeith/master
amrlabib Jul 20, 2023
4ed2b17
Merge pull request #99 from amrlabib/dependabot/npm_and_yarn/semver-5…
amrlabib Jul 20, 2023
f696cb5
Merge pull request #100 from amrlabib/dependabot/npm_and_yarn/word-wr…
amrlabib Jul 20, 2023
62cdb36
update docs
amrlabib Jul 20, 2023
71c6dc7
Bump @babel/traverse from 7.21.5 to 7.23.2
dependabot[bot] Oct 19, 2023
4011447
Bump follow-redirects from 1.15.2 to 1.15.4
dependabot[bot] Jan 10, 2024
8393e4a
fix: typo
OFK0 Jun 25, 2024
ea493f1
Merge pull request #104 from amrlabib/dependabot/npm_and_yarn/follow-…
amrlabib Oct 20, 2024
3795f57
Merge pull request #103 from amrlabib/dependabot/npm_and_yarn/babel/t…
amrlabib Oct 20, 2024
0127c2d
Merge pull request #105 from OFK0/typo-fix
amrlabib Oct 20, 2024
cfab581
update docs and bump version
amrlabib Oct 20, 2024
a0aa036
npm audit fix
amrlabib Oct 20, 2024
1883b13
Bump http-proxy-middleware from 2.0.6 to 2.0.7
dependabot[bot] Oct 26, 2024
c67276f
Bump cross-spawn from 7.0.3 to 7.0.6
dependabot[bot] Nov 24, 2024
b3b42eb
Bump path-to-regexp and express
dependabot[bot] Dec 6, 2024
6f4bbe6
Feature/support milliseconds (#116)
amrlabib Mar 5, 2025
ac6159b
Merge pull request #113 from amrlabib/dependabot/npm_and_yarn/multi-6…
amrlabib Mar 5, 2025
35fa439
Merge pull request #112 from amrlabib/dependabot/npm_and_yarn/cross-s…
amrlabib Mar 5, 2025
b334ccd
Merge pull request #111 from amrlabib/dependabot/npm_and_yarn/http-pr…
amrlabib Mar 5, 2025
b489b73
Bump serialize-javascript from 6.0.1 to 6.0.2
dependabot[bot] Mar 5, 2025
d4aa580
version 4.0.0
amrlabib Mar 5, 2025
6e03ec5
update types
amrlabib Mar 5, 2025
325a96f
Merge pull request #117 from amrlabib/dependabot/npm_and_yarn/seriali…
amrlabib Mar 5, 2025
417a4d6
Typescript (#118)
amrlabib Mar 17, 2025
9ff90b1
useStopwatch pause minor fix
amrlabib Mar 17, 2025
b04c12f
version 4.0.2
amrlabib Mar 17, 2025
327e1c1
prepare script
amrlabib Mar 17, 2025
aa8d0db
update npmignore to include anything inside dist and ignore demo folder
amrlabib Mar 18, 2025
d42d508
version 4.0.4
amrlabib Mar 18, 2025
831cf47
handle missing expirytimestamp
amrlabib Mar 18, 2025
cd20d2f
version 4.0.5
amrlabib Mar 18, 2025
a4abf8c
Bump http-proxy-middleware from 2.0.7 to 2.0.9 (#120)
dependabot[bot] Jun 10, 2025
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
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

7 changes: 3 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ build
!.eslintrc
yarn-error.log
dev-dist
readme-images

docs
demo
*.js
!dist/index.js

!dist/**/*
*.html
45 changes: 0 additions & 45 deletions app/App.js

This file was deleted.

77 changes: 77 additions & 0 deletions demo/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';
import styled, { createGlobalStyle } from 'styled-components';
import UseTimerDemo from './components/UseTimerDemo';
import UseStopwatchDemo from './components/UseStopwatchDemo';
import UseTimeDemo from './components/UseTimeDemo';

const GlobalStyle = createGlobalStyle`
html, body {
margin: 0;
font-family: Arial;
text-align: left;
color: #404549;
}
h2 {
margin-top: 20px;
}
`;

const Container = styled.div`
width: 1170px;
margin-left: auto;
margin-right: auto;
`;

const HeaderBG = styled.div`
background-color: #404549;
`;

const Header = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
& h1 {
margin: 20px 0;
}
`;

const H1 = styled.h1`
color: white;
`;

const Separator = styled.div`
height: 0px;
margin-top: 30px;
border: dashed 2px #404549;
`;

export default function App() {
const time = new Date();
time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
return (
<div>
<GlobalStyle />
<HeaderBG>
<Container>
<Header>
<H1>react-timer-hook</H1>
<div>
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=star&count=true&size=large" frameBorder="0" scrolling="0" width="160" height="30" title="GitHub" />
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=fork&count=true&size=large" frameBorder="0" scrolling="0" width="126" height="30" title="GitHub" />
</div>
</Header>
</Container>
</HeaderBG>
<Container>
<p>
React timer hook is a custom <a href="https://reactjs.org/docs/hooks-intro.html" target="_blank">react hook</a> built to handle timer, stopwatch, and time logic/state in your react component.
</p>
<UseTimerDemo expiryTimestamp={time} interval={20} />
<Separator />
<UseStopwatchDemo interval={20} />
<Separator />
<UseTimeDemo interval={20} />
</Container>
</div>
);
}
18 changes: 18 additions & 0 deletions demo/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import styled from 'styled-components';

const ButtonStyled = styled.button`
border-radius: 5;
margin: 0 10px 0 0px;
outline: none;
border: none;
padding: 6px 14px;
color: #404549;
border-radius: 3px;
border: solid 1px #404549;
&: hover {
box-shadow: 0 0 11px rgba(33,33,33,.2);
cursor: pointer;
}
`;

export default ButtonStyled;
85 changes: 85 additions & 0 deletions demo/components/Digit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import styled from 'styled-components';

const Container = styled.div`
display: flex;
flex-direction: column;
align-items: center;
margin: 0 5px;
&: first-child {
margin-left: 0;
}
`;

const Title = styled.span`
font-size: 12px;
margin-bottom: 5px;
`;

const DigitContainer = styled.div`
display: flex;
flex-direction: row;
padding: 0;
`;

const SingleDigit = styled.span`
position: relative;
display: flex;
flex: 0 1 25%;
font-size: 30px;
background-color: #404549;
border-radius: 5px;
padding: 10px 12px;
color: white;
margin-right: 2px;
&:last-child {
margin-right: ;
}
&:after {
position: absolute;
left: 0px;
right: 0px;
top: 50%;
bottom: 50%;
content: "";
width: '100%';
height: 2px;
background-color: #232323;
opacity: 0.4;
}
`;

type DigitType = {
value: number,
title: string,
isMIlliseconds?: boolean;
};

export default function Digit({ value, title, isMIlliseconds }: DigitType) {
const digits = value.toString().padStart(4, '0');
return (
<Container>
<Title>{title}</Title>
<DigitContainer>
{isMIlliseconds ?
<>
<SingleDigit>
{digits[0]}
</SingleDigit>
<SingleDigit>
{digits[1]}
</SingleDigit>
</>
:
null
}
<SingleDigit>
{digits[2]}
</SingleDigit>
<SingleDigit>
{digits[3]}
</SingleDigit>
</DigitContainer>
</Container>
);
}
56 changes: 56 additions & 0 deletions demo/components/TimerStyled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import styled from 'styled-components';
import Digit from './Digit';

const TimerContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 30px;
`;

const SepartorContainer = styled.span`
display: flex;
flex-direction: column;
align-items: center;
align-self: flex-end;
margin: 0 0 10px 0px;
`;

const Separtor = styled.span`
display: inline-block;
width: 6px;
height: 6px;
background-color: #404549;
border-radius: 6px;
margin: 5px 0px;
`;

type TimerType = {
milliseconds: number,
seconds: number,
minutes: number,
hours: number,
days?: number,
enableMilliseconds: boolean;
};

export default function TimerStyled({ milliseconds, seconds, minutes, hours, days, enableMilliseconds }: TimerType) {
return (
<TimerContainer>
{days !== undefined ? <Digit value={days} title="DAYS" /> : null}
{days !== undefined ? (<SepartorContainer><Separtor /><Separtor /></SepartorContainer>): null}
<Digit value={hours} title="HOURS" />
<SepartorContainer><Separtor /><Separtor /></SepartorContainer>
<Digit value={minutes} title="MINUTES" />
<SepartorContainer><Separtor /><Separtor /></SepartorContainer>
<Digit value={seconds} title="SECONDS" />
{enableMilliseconds ?
<>
<SepartorContainer><Separtor /><Separtor /></SepartorContainer>
<Digit value={milliseconds} title="MILLISECONDS" isMIlliseconds />
</>
: null }
</TimerContainer>
);
}
28 changes: 28 additions & 0 deletions demo/components/UseStopwatchDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { useStopwatch } from '../../src/index';
import Button from './Button';
import TimerStyled from './TimerStyled';

export default function UseStopwatchDemo({ interval }: { interval: number}) {
const {
milliseconds,
seconds,
minutes,
hours,
days,
start,
pause,
reset,
} = useStopwatch({ interval });


return (
<div>
<h2>UseStopwatch Demo</h2>
<TimerStyled milliseconds={milliseconds} seconds={seconds} minutes={minutes} hours={hours} days={days} enableMilliseconds={interval < 1000} />
<Button onClick={start}>Start</Button>
<Button onClick={pause}>Pause</Button>
<Button onClick={() => reset()}>Reset</Button>
</div>
);
}
21 changes: 21 additions & 0 deletions demo/components/UseTimeDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { useTime } from '../../src/index';
import TimerStyled from './TimerStyled';

export default function UseTimeDemo({ interval }: { interval: number}) {
const {
milliseconds,
seconds,
minutes,
hours,
} = useTime({ interval });

return (
<div>
<h2>UseTime Demo</h2>
<div>
<TimerStyled milliseconds={milliseconds} seconds={seconds} minutes={minutes} hours={hours} enableMilliseconds={interval < 1000} />
</div>
</div>
);
}
Loading