@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
30 lines • 1.5 kB
text/typescript
import type { ChunkComponentProps, CreateChunkConfig } from "./types.mjs";
/** Result of {@link useChunk}. */
export interface UseChunkResult<P> {
/** The chunk's data: the loaded value, or the initial/preloaded value while loading. */
data: P | undefined;
/** `true` until the full data has loaded. */
loading: boolean;
/** `true` while a background refresh is in flight; the current `data` stays visible. */
revalidating: boolean;
/**
* Re-run the `data`-mode loader and swap in fresh data, keeping the current
* data visible meanwhile (stale-while-revalidate). Aborts any prior in-flight
* refresh. A no-op for non-`data` sources or when no source resolves.
*/
refresh: () => Promise<void>;
}
/**
* Load a single chunk's data on the client (props-context-layering: when the
* data already arrived via `preloaded`, no fetch happens). Handles the
* `controlled`/`preloaded` short-circuit and a quick `initial` value shown while
* the full `data`-mode `load` resolves.
*
* Returns a `refresh()` that re-runs the loader with stale-while-revalidate, and
* (opt-in via `config.revalidateOnIdle`) schedules one such refresh on the first
* idle period after the chunk has loaded.
*
* Used by the component {@link createCoordinatedLazy} produces; consumers can
* also call it directly for a custom chunk renderer.
*/
export declare function useChunk<T extends {}, P, O>(config: CreateChunkConfig<T, P, O>, props?: ChunkComponentProps<T, P, O>): UseChunkResult<P>;