use-fetch-api
v1.1.0
Published
A custom React hook that uses the Fetch API.
Downloads
13
Readme
use-fetch-api
A custom React hook for fetching data using the Fetch API.
Getting started
To use this hook simply run the following command: npm install use-fetch-api
. After installing the package you can start using it in your project like so:
import { useFetch } from 'use-fetch-api';
const App = () => {
const { data, loading, error } = useFetch('https://www.your-url.com', 'json');
return <div>{data}</div>;
}
export default App;
API
The hooks receives three arguments of which two are required, these areguments are url
, resolver
, options
.
url: string
– The API endpoint you're trying to get data fromresolver: array | Buffer | blob | formData | json | text
– The way in which you want your data to be resolved, most often this will bejson
.options: RequestInit
– The options that are used in the regular fetch API.