error
Description: Defines how long an error is kept in the cache.
Default Value: 500 milliseconds.
- How To: Adjust the
errorduration (in milliseconds) to control how long an error state persists for a given key. A shorter duration might be useful for transient errors that you expect to resolve quickly, allowing for quicker re-attempts. A longer duration can prevent repeated, immediate re-fetches for persistent errors.// Correct: Keep transient errors for 1 second, allowing quick retryuseFetch('volatile-api',fetchVolatileData,{ error: 1000 } // Keep error for 1 second);// Correct: Keep persistent errors for 5 minutes to avoid hammering the APIuseFetch('stable-api',fetchStableData,{ error: 5 * 60 * 1000 } // Keep error for 5 minutes); - Best Practice: Setting
errortoo short might cause repeated error fetches, potentially leading to rate limiting or unnecessary server load. Setting it too long might hide a resolved issue from the user.