Skip to content

createUseRequestComponent ​

A factory that wraps useRequest as a render component. It is useful when a team wants to organize loading, error, and success states with template slots while keeping useRequest cache, polling, refresh deps, and plugin behavior.

Code demonstration ​

Basic usage ​

API ​

typescript
const UseRequest = createUseRequestComponent<TData, TParams, TFormatResult>()
PropertyDescriptionTypeDefault
serviceRequest service(...params: TParams) => Promise<TData>-
manualWhether to trigger manuallybooleanfalse
readyWhether the request is readyRef<boolean> | booleantrue
refreshDepsDependencies that refresh the request when changedany[][]
pluginsuseRequest pluginsUseRequestPlugin[][]
formatResultFormat response data(res: TData) => TFormatResult-
SlotDescription
defaultRendered outside loading/error states. Receives the full useRequest result
loadingRendered while loading
errorRendered on error. Receives { error }

Source ​

Source · Document · Demo

Released under the MIT License.