( initialValue = 10 )
| 2 | |
| 3 | |
| 4 | export 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 |
no outgoing calls
no test coverage detected