resetError
Description: A utility function returned by the useFetch hook used to manually clear an error state from the cache and the hook's local state.
- How To: Destructure
resetErrorfrom theuseFetchreturn object. Call it to dismiss an active error state, which is useful for "Try Again" UI patterns or manual error handling.// Correct: Using resetError to clear a failed stateconst { error, resetError, refetch } = useFetch({key: 'user-profile',data: () => actionGetUser()});if (error) {return (<ErrorBannermessage="Failed to load profile"onDismiss={() => resetError()} // Clears the error state in cacheonRetry={() => refetch()} // Manually triggers a new fetch/>);} - Best Practice: Use
resetErrorwhen you want to return the UI to a clean (non-error) state without necessarily forcing an immediate refetch. It allows for a better user experience by letting the user decide when to retry.
Why
- Provides granular control over the error lifecycle.
- Enables "Dismiss" functionality for error messages.
- Prevents stale error states from blocking subsequent UI interactions.