memoize debounced function
This commit is contained in:
parent
d1a7dca46b
commit
0a35bca650
|
@ -18,6 +18,7 @@ export function debounce (fn, time) {
|
|||
|
||||
export default function useDebounceCallback (fn, time, deps = []) {
|
||||
const [args, setArgs] = useState([])
|
||||
useEffect(debounce(() => fn(...args), time), [fn, time, args, ...deps])
|
||||
const memoFn = useCallback(fn, deps)
|
||||
useEffect(debounce(() => memoFn(...args), time), [memoFn, time, args, ...deps])
|
||||
return useCallback((...args) => setArgs(args), [])
|
||||
}
|
||||
|
|
|
@ -302,6 +302,12 @@ export function LnAddrWithdrawal () {
|
|||
const [formSchema, setFormSchema] = useState(lnAddrSchema())
|
||||
|
||||
const onAddrChange = useDebounceCallback(async (formik, e) => {
|
||||
if (!e?.target?.value) {
|
||||
setAddrOptions(defaultOptions)
|
||||
setFormSchema(lnAddrSchema())
|
||||
return
|
||||
}
|
||||
|
||||
let options
|
||||
try {
|
||||
options = await lnAddrOptions(e.target.value)
|
||||
|
@ -313,7 +319,7 @@ export function LnAddrWithdrawal () {
|
|||
|
||||
setAddrOptions(options)
|
||||
setFormSchema(lnAddrSchema(options))
|
||||
}, 500, [lnAddrOptions, lnAddrSchema])
|
||||
}, 500, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
Loading…
Reference in New Issue