useContinuousRetry

Automates retries of a callback function until it succeeds with useContinuousRetry

Install:

Note: This hook depends on React’s experimental useEffectEvent.

npm i @uidotdev/usehooks@experimental react@experimental react-dom@experimental

Description:

The useContinuousRetry hook allows you to repeatedly call a specified callback function at a defined interval until the callback returns a truthy value, indicating a successful resolution. This hook is particularly handy when dealing with asynchronous operations or API calls that may fail temporarily and need to be retried automatically. It encapsulates the logic of retrying and provides a clean interface to handle retry-related states, such as whether the retry process has resolved or not.

Parameters

NameTypeDescription
callbackfunctionThe callback function to be executed repeatedly until it returns a truthy value.
intervalnumber(Optional) The interval in milliseconds at which the callback function is executed. Default value is 100 milliseconds.
optionsobject(Optional) An object containing a maxRetries property which tells useContinuousRetry the maximum amount of retry attempts it should make before stopping

Return Value

TypeDescription
booleantrue if the callback function has resolved (returned a truthy value), false otherwise.

Demo:

Example:

More Hooks:

Sort: