react-url-fetcher
v1.0.0
Published
A React hook to fetch data using fetch API with useState and useEffect, including loading and error states.
Downloads
4
Maintainers
Readme
react-url-fetcher
A simple and lightweight React hook to fetch data from any URL using the Fetch API with React's useState and useEffect.
Includes built-in support for loading and error states.
Features
- Fetch data from a URL with ease.
- Automatically tracks loading and error states.
- Minimal and dependency-free (except React).
- Written with modern React hooks.
Installation
npm install react-url-fetcheror with Yarn
yarn add react-url-fetcherUsage
import React from 'react';
import { useApi } from 'react-url-fetcher';
function App() {
const { data, error, loading } = useApi('https://jsonplaceholder.typicode.com/posts');
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return (
<ul>
{data?.map(post => (
<li key={post.id}>{post.title}</li>
))}
</ul>
);
}
export default App;
Contributing
Feel free to open issues or submit pull requests!
Credits
Implementation (c) 2025 Gulam Ashraf. MIT LICENSE
