MCPcopy Create free account
hub / github.com/Klerith/react-hooks / useCounter

Function useCounter

src/hooks/useCounter.js:4–29  ·  view source on GitHub ↗
( initialValue = 10 )

Source from the content-addressed store, hash-verified

2
3
4export const useCounter = ( initialValue = 10 ) => {
5
6 const [ counter, setCounter ] = useState( initialValue )
7
8 const increment = ( value = 1 ) => {
9 setCounter( counter + value );
10 }
11
12 const decrement = ( value = 1 ) => {
13 // if ( counter === 0 ) return;
14
15 setCounter( counter - value );
16 }
17
18 const reset = () => {
19 setCounter( initialValue );
20 }
21
22 return {
23 counter,
24 increment,
25 decrement,
26 reset,
27 }
28
29}
30

Callers 5

MultipleCustomHooksFunction · 0.90
CounterWithCustomHookFunction · 0.90
LayoutFunction · 0.90
MemoHookFunction · 0.90
MemorizeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected