UNPKG
@hakuna-matata-ui/hooks
Version:
latest (1.7.2)
1.7.2
1.7.1
React hooks for Chakra components
github.com/monacohq/hakuna-matata-ui
monacohq/hakuna-matata-ui
@hakuna-matata-ui/hooks
/
src
/
use-previous.ts
12 lines
(8 loc)
•
212 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
import { useRef, useEffect }
from
"react"
export function
usePrevious
<
T
>(
value
: T
)
{
const
ref
= useRef<T | undefined>() useEffect(() => {
ref
.current =
value
}, [
value
])
return
ref
.current
as
T }