Function
useAsync
(
func: () => Promise<T> | undefined | null,
deps = [],
)
Source from the content-addressed store, hash-verified
| 1 | import { useEffect, useRef, useState } from 'react' |
| 2 | |
| 3 | export function useAsync<T>( |
| 4 | func: () => Promise<T> | undefined | null, |
| 5 | deps = [], |
| 6 | ) { |
| 7 | const ref = useRef(func) |
| 8 | ref.current = func |
| 9 | const [value, setValue] = useState<T>() |
| 10 | |
| 11 | useEffect(() => { |
| 12 | ref.current()?.then(setValue) |
| 13 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 14 | }, deps) |
| 15 | |
| 16 | return value |
| 17 | } |
Callers
nothing calls this directly
Tested by
no test coverage detected