
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
use-api-handler
Advanced tools
A versatile hook for handling API requests in React applications.
npm install use-api-handler
import React from 'react';
import useApiHandler from 'use-api-handler';
function App() {
const { data, loading, error, sendRequest } = useApiHandler('https://api.example.com/data');
return (
<div>
{loading && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
{data && <pre>{JSON.stringify(data, null, 2)}</pre>}
<button onClick={() => sendRequest('GET')}>Fetch Data</button>
</div>
);
}
export default App;
Simplifies API requests in React applications Pagination support with fetchPaginatedData function Caching of API responses using fetchCachedData Error handling and automatic retries with sendRetriableRequest Custom request headers and authentication support Clean cancellation and cleanup on unmounting
Check out the examples directory for more usage examples and integration scenarios.
useApiHandler(initialUrl, initialData, debounceDelay) Parameters initialUrl: Initial API endpoint URL. initialData (optional): Initial data for the hook. Default: null. debounceDelay (optional): Delay in milliseconds for URL debouncing. Default: 300. Returns An object with the following properties and functions:
data: The fetched data. loading: A boolean indicating if the request is in progress. error: An error object if the request encountered an error. setUrl(url): Update the API endpoint URL. sendRequest(method, requestData, requestConfig): Send a custom API request. fetchPaginatedData(page, pageSize): Fetch paginated data. fetchCachedData(): Fetch cached data or perform a new request if not cached. sendAuthenticatedRequest(method, requestData, token): Send an authenticated API request. sendRetriableRequest(method, requestData, requestConfig, retries, delay): Send a retriable API request.
Contributions are welcome! Please read CONTRIBUTING.md for details on how to contribute to this project.
This project is licensed under the MIT License. See LICENSE for more information.
FAQs
A versatile hook for handling API requests in React applications.
We found that use-api-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.