Lets a component load one thing from the API the first time it's needed, and keep it for as long as its key holds, as the profile's lazy tabs do.

Functions

f
useFetchState<T>(
key: string | undefined,
load: (signal: AbortSignal) => Promise<T>,
unnamed 2?: FetchStateOptions<T>
): UseFetchStateResult<T>

Returns what load resolves to for key, loaded the first time it is enabled, and kept afterwards. A new key starts over and aborts the load of the last one, as leaving the page does; an undefined key loads nothing. The key must change with whatever the load depends on, the viewer included when it is signed in. load must reject with an Error, as expectOk does, whose message it shows.

Interfaces

I
FetchStateOptions

Passed to useFetchState.

  • enabled: boolean

    False until it should load, as the profile's tabs pass "this tab is open". Turning it off doesn't abort a load under way, so those tabs finish loading in the background. True by default.

  • initial: T

    It holds the data already at hand for a new key, as a feed restored from useFeedCache, which starts loaded and isn't loaded again. It is read only when the key changes.

I
UseFetchStateResult

Returned by useFetchState.

Type Aliases

T
FetchState<T> = LoadState<{ data: T; }>

Held by useFetchState, and passed on to ListState.