Skip to content

A super simple React hook for fetching and caching HTTP responses. This hook uses the browsers Fetch API to make requests.

Notifications You must be signed in to change notification settings

tjcafferkey/usefetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useFetch();

A super simple React hook for fetching and caching HTTP responses. This hook uses the browsers Fetch API to make requests.

Installation

npm install @tjcafferkey/usefetch

Usage

import useFetch from '@tjcafferkey/usefetch';

const { data, status } = useFetch( {
    url: 'https://some-domain/api/v1/some-endpoint',
    shouldExecute: true // Optional: Defaults to true: true | false
} );

For a list of optional configation options please see the MDN Fetch documentation. All the options apply except method and body.

Response Schema

{
    // `status` is a string representing the requests current state.
    status: 'LOADING', // 'IDLE' | 'LOADING' | 'SUCCESS' | 'ERROR';

    // `data` is the response that was provided by the server
    data: {},
}

About

A super simple React hook for fetching and caching HTTP responses. This hook uses the browsers Fetch API to make requests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published