README
@solid-primitives/fetch
Creates a primitive to support abortable HTTP requests. If any reactive request options changes, the request is aborted automatically.
Installation
npm install @solid-primitives/fetch
# or
yarn add @solid-primitives/fetch
How to use it
const [resource, { mutate, refetch, abort }] = createFetch<T>(
requestInfo: Accessor<RequestInfo> | RequestInfo,
requestInit?: Accessor<RequestInit> | RequestInit,
options?: { initialValue: T, name?: string }
);
resource(): T
resource.aborted: boolean
resource.error: Error | any | undefined
resource.loading: boolean
resource.status: number | null
Remember, just like with createResource
, you will need an <ErrorBoundary>
to catch the errors, even if they are accessible inside the resource. Otherwise, uncaught errors might disrupt your application.
Demo
TODO
Changelog
Expand Changelog
0.0.100
Initial release adapted from https://github.com/microcipcip/vue-use-kit/blob/master/src/functions/useFetch/useFetch.ts.
0.0.105
Improve test setup
0.0.106
Add tests for error case, remove stray console.warn
1.0.5
Released CJS and SSR support.
1.0.6
Added missing server entry compile in TSUP and updated to Solid.