Package Exports
- @nicolastoulemont/use-fetch
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nicolastoulemont/use-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Use-form
This use-fetch utility hook implement state-while-revalidate data-fetching with a cache using sha-256 hashs of the request url and params as keys.
Disclaimer
This is a work in progress tool and mainly aimed at my personal use accross my projects.
Installation
npm install @nicolastoulemont/use-fetch
or
yarn add @nicolastoulemont/use-fetchUsage
- Basic usage
import { useFetch } from '@nicolastoulemont/use-fetch';
export function BasicComponent() {
const { response, loading, error, fetchy } = useFetch(
'[DATA_SOURCE_URL]',
fetchOptions
);
return (
<div>
<button onClick={fetchy}></button>
{loading && <div>Loading...</div>}
{response && <div>{JSON.stringify(response, null, 2)}</div>}
</div>
);
}Built with
Versionning
This tool use SemVer for versioning.
Licence
MIT