0.0.6 • Published 3 years ago

@ahmetelgun/usefetch v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

useFetch

Fetch hook for React

Installation

npm install @ahmetelgun/usefetch

Usage

import useFetch from "@ahmetelgun/usefetch";
.
.
const [response, loading, error] = useFetch("url");

if(loading){
    return <div>loading</div>;
}
else if(error){
    return <div>error</div>;
}
else if (response){
    //use response
}
{ //response schema
    status: 200,
    data: {
        //data
    }
}
import useFetch from "@ahmetelgun/usefetch";
.
.
const [response, loading, error, callFetch] = useFetch();
if(expression){
    callFetch("url")
}
if(another_expression){
    callFetch("url") 
    //if you call callFetch function before the old request ends, old request is aborted.
}
import useFetch from "@ahmetelgun/usefetch";
.
.
const options = {
    method: 'POST',
    mode: 'cors', 
    cache: 'no-cache',
    credentials: 'same-origin',
    headers: {
      'Content-Type': 'application/json'
    }
}
const [response, loading, error, callFetch] = useFetch("url", options);
.
.
callFetch("url", options /*or different options*/)
//data, loading and error are reset every time you call callFetch function.
0.0.6

3 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago