use-form-auto-save
Version:
A customizable React hook for automatically saving and restoring form data with support for localStorage, sessionStorage, and external APIs.
19 lines • 796 B
JavaScript
import { useEffect } from 'react';
export const useRetryHandler = ({ shouldRetry, retryCount, maxRetries, logDebug, onRetry, onRetryExhausted, }) => {
useEffect(() => {
if (!shouldRetry)
return;
if (retryCount >= maxRetries) {
logDebug(`Max retry limit (${maxRetries}) reached. Auto-save will not retry.`);
onRetryExhausted?.();
return;
}
const retryDelay = Math.pow(2, retryCount) * 1000;
logDebug(`Retrying auto-save in ${retryDelay}ms...`);
const timer = setTimeout(() => {
onRetry();
}, retryDelay);
return () => clearTimeout(timer);
}, [shouldRetry, retryCount, maxRetries, logDebug, onRetry, onRetryExhausted]);
};
//# sourceMappingURL=useRetryHandler.js.map