Skip to content

A library for handling asynchronous functions with Runes

Notifications You must be signed in to change notification settings

C-Sinclair/rune-query

Repository files navigation

Rune Query

A library for handling asynchronous functions with Runes

.github/workflows/test.yaml

Usage

// in your svelte component or .svelte.js/ts files
let { query, invalidate } = createQuery(async (args) => { .../* some data to be fetched */ });

let q = query({ id: 123 });

// loading is true initially until the asynchronous function completes
q.loading;

// The data can be found in the data key
q.data;

// If an error is thrown in your function, it will be available under the error key
q.error;

// later, you may wish to invalidate the current data, and refetch
invalidate();
// That's it, the reactive `data` and `loading` values above will reactively update

Type inference

The type for data is inferred from the ReturnType of your async function. This means no manually typing expected types etc.

let { query } = createQuery(async () => 123);
query.data; // number | undefined
let { query } = createQuery(async () => "hello world");
query.data; // string | undefined

// when loading is complete, the data type will resolve to just the type (not undefined anymore)
if (!query.loading) {
  query.data; // string
}

About

A library for handling asynchronous functions with Runes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published