Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c60c14d

Browse files
committed
Update useCounter example to use updater function, As per #47
1 parent a8ef8c8 commit c60c14d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

‎docs/usage/advanced-hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useState, useCallback } from 'react'
1515

1616
export default function useCounter(initialValue = 0) {
1717
const [count, setCount] = useState(initialValue)
18-
const increment = useCallback(() => setCount(count + 1), [count])
18+
const increment = useCallback(() => setCount((x) => x + 1), [])
1919
return { count, increment }
2020
}
2121
```
@@ -46,7 +46,7 @@ import { useState, useCallback } from 'react'
4646

4747
export default function useCounter(initialValue = 0) {
4848
const [count, setCount] = useState(initialValue)
49-
const increment = useCallback(() => setCount(count + 1), [count])
49+
const increment = useCallback(() => setCount((x) => x + 1), [])
5050
const reset = useCallback(() => setCount(initialValue), [initialValue])
5151
return { count, increment, reset }
5252
}

‎docs/usage/basic-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useState, useCallback } from 'react'
1515

1616
export default function useCounter() {
1717
const [count, setCount] = useState(0)
18-
const increment = useCallback(() => setCount(count + 1), [count])
18+
const increment = useCallback(() => setCount((x) => x + 1), [])
1919
return { count, increment }
2020
}
2121
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /