FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
uniswap_interface_sc/apps/web/src/hooks/useLast.ts at main · stringcode86/uniswap_interface_sc · GitHub
stringcode86
uniswap_interface_sc
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
uniswap_interface_sc
/
apps
/
web
/
src
/
hooks
/
useLast.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
20 lines (19 loc) · 613 Bytes
Breadcrumbs
uniswap_interface_sc
/
apps
/
web
/
src
/
hooks
/
useLast.ts
Copy path
File metadata and controls
20 lines (19 loc) · 613 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import
{
useEffect
,
useState
}
from
'react'
/**
* Returns the last value of type T that passes a filter function
*
@param
value changing value
*
@param
filterFn function that determines whether a given value should be considered for the last value
*/
export
default
function
useLast
<
T
>
(
value
:
T
,
filterFn
?:
(
value
:
T
)
=>
boolean
)
:
T
{
const
[
last
,
setLast
]
=
useState
<
T
>
(
value
)
useEffect
(
(
)
=>
{
setLast
(
(
last
)
=>
{
const
shouldUse
:
boolean
=
filterFn
?
filterFn
(
value
)
:
true
if
(
shouldUse
)
{
return
value
}
return
last
}
)
}
,
[
filterFn
,
value
]
)
return
last
}
Back
|
FazBrowse Home
|
New Git URL