MCPcopy Create free account
hub / github.com/pacexy/flow / useAsync

Function useAsync

apps/reader/src/hooks/useAsync.ts:3–17  ·  view source on GitHub ↗
(
  func: () => Promise<T> | undefined | null,
  deps = [],
)

Source from the content-addressed store, hash-verified

1import { useEffect, useRef, useState } from 'react'
2
3export 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

Calls 1

currentMethod · 0.80

Tested by

no test coverage detected