Skip to content

Kalaiarasan-Dev/use-fetch-cache

Repository files navigation

useFetch - Production React Hook for Data Fetching

TypeScript React License: MIT npm version

A type-safe React hook for data fetching with caching, error handling, and request cancellation.

📖 Table of Contents

🔭 Overview

useFetch is a production-ready custom React hook that solves common data fetching challenges. Built with TypeScript, it provides automatic caching, loading states, error handling, and request cancellation out of the box.

Key Benefits

  • Zero external dependencies - Pure React implementation
  • Full TypeScript support - Complete type safety with generics
  • Intelligent caching - In-memory cache with configurable TTL
  • Race condition safe - Automatic request cancellation
  • Simple, predictable API - Easy to learn, powerful to use

✨ Features

Feature Description
🔷 TypeScript Full generic support for type safety
💾 Caching In-memory cache with configurable TTL
Loading States Built-in loading state management
⚠️ Error Handling Comprehensive error catching
🛑 Request Cancellation Aborts in-flight requests on unmount
🎯 Conditional Fetching Fetch only when needed
🔄 Manual Refetch Programmatic refresh capability
📞 Callbacks onSuccess and onError hooks
⏱️ Timeout Support Configurable request timeout
🔍 Stale Detection Check if cached data is stale

📦 Installation

# npm
npm install @kalaiarasan/use-fetch-hook

# yarn
yarn add @kalaiarasan/use-fetch-hook

Requirements
Node.js >= 18.0.0

React >= 18.0.0

TypeScript >= 5.0.0


Releases

No releases published

Packages

 
 
 

Contributors