UNPKG
common-hook
Version:
latest (1.3.2)
1.3.2
1.2.0
1.1.0
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.0.3
0.0.2
0.0.1
提供项目中常用的 React Hooks
github.com/JainaXiong/common-hook
JainaXiong/common-hook
common-hook
/
es
/
advanced
/
useLatest.js
13 lines
(12 loc)
•
292 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
import
{ useRef }
from
"react"
;
/** *
@name
返回的永远是最新值 *
@description
返回当前最新值的 Hook,可以避免闭包问题 *
@example
* useLatest(fn) */
export
const
useLatest
= (
value
) => {
const
ref =
useRef
(value); ref.
current
= value;
return
ref; };