Fetch-Loader-React
Fetch-Loader-React is a simple and lightweight React Component which allows you to display a custom loader while fetching assynchronously one or more requests.
- Supports fetch api and axios
- Supports multiple ansynchronous fetches
- Requires React 16.8.0 or above
See an example using multiple fetches with fetch api and axios.
Installation
npm i fetch-loader-react
How to use
;
Using Fetch API
const fetchPromise1 = );const fetchPromise2 = );
<FetchLoader fetch= fetchPromise1 fetchPromise2 type="json"> { if loading return <YourLoader /> if err console; return; return <YourComponent res=res />; } </FetchLoader>
Using Axios
const axiosPromise1 = axios);const axiosPromise2 = axios);
<FetchLoader fetch= axiosPromise1 axiosPromise2 > { if loading return <YourLoader /> if err console; return; return <YourComponent res=res />; } </FetchLoader>
Props
Name | Type | Values | Description |
---|---|---|---|
fetch |
Object |
Promise |
The fetch or axios promise |
type |
String |
'json' , 'text' , 'blob' , 'arrayBuffer' , 'formData' |
The type of the fetched data. Must not be provided when using axios. |
Authors
- Marc Leonetti
- Sven Mathieu