0.4.0 • Published 12 months ago

vue-unquery v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

🪺 vue-unquery

NPM version

Lightweight data management for Vue in suspense & non-suspense contexts.

Basically an identical fork of TurboVue, but also suited for non-suspense setups.

All the credits to Erik C. Forés for his amazing work.

Key Features

  • 🎠 Create a query resource:
    • Suspense contexts: useAsyncQuery
    • Non-suspense contexts: useQuery
  • ⛲️ Support for lazy fetching via immediate: false option in non-suspense environments

Usage

Suspense Context

const [post, { isRefetching, refetch, mutate, error }] = await useAsyncQuery<Post>(
  () => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
)

Non-Suspense Context

const [post, { isRefetching, refetch, mutate, error }] = useQuery<Post>(
  () => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
)

Prevent initial data fetching with immediate: false:

const [post, { isRefetching, refetch, mutate, error }] = useQuery<Post>(
  () => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
  { immediate: false }
)

// Later, call:
refetch()

Configuration

Note

All options from Turbo Query apply.

import { configure } from 'vue-unquery'

configure({
  async fetcher(key, { signal }) {
    const response = await fetch(key, { signal })
    if (!response.ok)
      throw new Error('Fetch request failed')
    return await response.json()
  },
})

License

MIT License © 2022-2023 Johann Schopplich

MIT License © 2022 Erik C. Forés

0.4.0

12 months ago

0.3.4

1 year ago

0.3.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.2.0

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.0

2 years ago