mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 18:08:11 +09:00
fix(web): rename hooks file
This commit is contained in:
18
web/src/util/hooks.js
Normal file
18
web/src/util/hooks.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export function useDeferredState(duration = 1000, initialValue = undefined) {
|
||||
const [response, setResponse] = useState(initialValue)
|
||||
const [innerValue, setInnerValue] = useState(initialValue)
|
||||
|
||||
useEffect(() => {
|
||||
const fn = setTimeout(() => {
|
||||
setResponse(innerValue)
|
||||
}, duration)
|
||||
|
||||
return () => {
|
||||
clearTimeout(fn)
|
||||
}
|
||||
}, [duration, innerValue])
|
||||
|
||||
return [response, setInnerValue]
|
||||
}
|
Reference in New Issue
Block a user