Skip to content

Commit

Permalink
Update counter
Browse files Browse the repository at this point in the history
  • Loading branch information
gromchen committed May 30, 2023
1 parent a196cdc commit 22e72b4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/useCounter/useCounter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, SetStateAction, useState } from 'react'
import { Dispatch, SetStateAction, useCallback, useState } from 'react'

interface UseCounterOutput {
count: number
Expand All @@ -11,9 +11,9 @@ interface UseCounterOutput {
function useCounter(initialValue?: number): UseCounterOutput {
const [count, setCount] = useState(initialValue || 0)

const increment = () => setCount(x => x + 1)
const decrement = () => setCount(x => x - 1)
const reset = () => setCount(initialValue || 0)
const increment = useCallback(() => setCount(x => x + 1), [])
const decrement = useCallback(() => setCount(x => x - 1), [])
const reset = useCallback(() => setCount(initialValue || 0), [initialValue])

return {
count,
Expand Down

0 comments on commit 22e72b4

Please sign in to comment.