react-native-fetch-kit
v0.1.0
Published
Resilient fetch utilities for React Native — timeouts, retries, and typed JSON helpers
Maintainers
Readme
react-native-fetch-kit
Resilient fetch utilities for React Native apps — timeouts, retries, typed JSON parsing, and a lightweight data-fetching hook.
Built by Rajan Kumar · Senior Frontend Developer · React Native
Pairs well with react-native-web3-kit for mobile Web3 apps.
Install
npm install react-native-fetch-kit
# or
yarn add react-native-fetch-kitFeatures
- Timeout support — abort slow requests automatically
- Retry with backoff — retry 408, 429, and 5xx responses
- Typed JSON helpers —
fetchJson,parseJson,FetchKitError - Query builders —
buildQuery,withQuery - React hook —
useFetchwith loading/error/refetch state
Usage
Fetch JSON with retries
import { fetchJson } from "react-native-fetch-kit";
const profile = await fetchJson<{ id: string; name: string }>(
"https://api.example.com/profile",
{ headers: { Authorization: "Bearer token" } },
{ timeoutMs: 8000, retries: 2 }
);Custom fetch wrapper
import { createFetcher } from "react-native-fetch-kit";
const api = createFetcher({ timeoutMs: 10_000, retries: 3 });
const response = await api("https://api.example.com/wallets");
const wallets = await response.json();Query params
import { withQuery } from "react-native-fetch-kit";
const url = withQuery("https://api.example.com/tokens", {
chainId: 1,
limit: 20,
});React hook
import { useFetch } from "react-native-fetch-kit";
function ProfileScreen() {
const { data, loading, error, refetch } = useFetch<{ name: string }>(
"https://api.example.com/me"
);
if (loading) return <Text>Loading...</Text>;
if (error) return <Text>{error.message}</Text>;
return (
<>
<Text>{data?.name}</Text>
<Button title="Refresh" onPress={refetch} />
</>
);
}API
| Export | Description |
|--------|-------------|
| createFetcher | Fetch wrapper with timeout + retry |
| fetchJson | Fetch and parse JSON in one call |
| parseJson | Parse JSON or throw FetchKitError |
| buildQuery | Build ?key=value query string |
| withQuery | Append query params to a URL |
| useFetch | React hook for API requests |
| FetchKitError | Normalized fetch error type |
Development
npm install
npm test
npm run buildLicense
MIT © Rajan Kumar
