@shoebcodes/useeasy
v1.0.5
Published
   in one line - 🔹 Simplified API fetching
- 🔹 Auto-refresh APIs on intervals
- 🔹 Retry logic on failure
- 🔹 Works with any async function
- 🔹 Zero configuration
- 🔹 Beginner-friendly
- 🔹 No dependencies except React
📦 Installation
npm install @shoebcodes/useeasy🧠 Hooks Included
1️⃣ useEasyAsync(asyncFn, deps?)
Run any async function and automatically manage:
loadingerrordatarun()
Example
import { useEasyAsync } from "@shoebcodes/useeasy";
function Component() {
const { data, loading, error, run } = useEasyAsync(() =>
fetch("/api/users").then(res => res.json())
);
return (
<>
{loading && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
<button onClick={run}>Reload</button>
<pre>{JSON.stringify(data, null, 2)}</pre>
</>
);
}2️⃣ useEasyFetch(url, options?)
A cleaner wrapper around fetch() with automatic state handling.
Example
import { useEasyFetch } from "@shoebcodes/useeasy";
function Users() {
const { data, loading, error, refetch } = useEasyFetch("/api/users");
return (
<>
<button onClick={refetch}>Refresh</button>
{loading && "Loading..."}
{error && error.message}
<pre>{JSON.stringify(data, null, 2)}</pre>
</>
);
}Options
useEasyFetch("/api/login", {
method: "POST",
body: { email: "[email protected]", password: "1234" },
headers: { Authorization: "Bearer token" }
});3️⃣ useEasyAutoFetch(url, { refresh, deps, retry })
Automatically refetch APIs on intervals or when dependencies change.
Example
import { useEasyAutoFetch } from "@shoebcodes/useeasy";
function LiveStats() {
const { data, loading } = useEasyAutoFetch("/api/stats", {
refresh: 3000,
retry: 2,
deps: []
});
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}⚙ API Options
| Option | Type | Default | Description | |------------|----------|---------|-------------| | deps | array | [] | Re-run when dependencies change | | refresh | number | null | Auto-refetch interval (ms) | | retry | number | 0 | Retry count on failure | | method | string | "GET" | HTTP method (fetch hooks) | | body | any | null | JSON request body | | headers | object | {} | Custom request headers |
🧩 Why useEasy?
React async code often looks like this:
useState...
useEffect...
try/catch...
loading...
error...
json()...With useEasy, it becomes:
const { data, loading } = useEasyFetch("/api/users");Clean. Minimal. Easy.
🛠 Contributing
PRs welcome after stable release.
📄 License
MIT License — free for personal and commercial use.
❤️ Support the Project
If useEasy saved you time, helped your code, or made your life easier,
consider supporting my open-source work:
👉 https://razorpay.me/@shoebfaizanmohammad
Every contribution — even ₹20 — motivates me to build more tools for developers.
