@laxpatel56237/testhook
v1.0.1
Published
Custom React hook for fetching data
Downloads
244
Readme
@lax/testhook
A simple and lightweight React hook for handling API requests using fetch.
📦 Installation
npm install @lax/testhook🚀 Usage
import { useFetch } from "@lax/testhook";
const App = () => {
const { data, loading, error } = useFetch(
"https://jsonplaceholder.typicode.com/posts"
);
if (loading) return <p>Loading...</p>;
if (error) return <p>{error}</p>;
return <pre>{JSON.stringify(data, null, 2)}</pre>;
};⚙️ API
useFetch(url, options)
Parameters:
url(string) → API endpointoptions(object, optional):method(string)headers(object)body(object)
📤 Returns
data→ response dataloading→ booleanerror→ error message
📝 Notes
- Automatically fetches data on component mount
- Uses native
fetchAPI - Designed for simple use cases
📄 License
MIT
