Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 8a7f40e

Browse files
feat: suspense method useAsyncQuery
1 parent b0299b3 commit 8a7f40e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,37 @@ All the credits to [Erik C. Forés](https://github.com/ConsoleTVs) for his amazi
1010

1111
## Key Features
1212

13-
- Non-suspense usage via `useQuery`
14-
- Support for lazy fetching via `immediate: false` option
13+
- 🎠 Create a query resource:
14+
- Suspense contexts: `useAsyncQuery`
15+
- Non-suspense contexts: `useQuery`
16+
- ⛲️ Support for lazy fetching via `immediate: false` option in non-suspense environments
17+
18+
## Usage
19+
20+
## Suspense Context
21+
22+
```ts
23+
const [post, { isRefetching, refetch, mutate, error }] = await useAsyncQuery<Post>(
24+
() => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
25+
)
26+
```
27+
28+
## Non-Suspense Context
29+
30+
```ts
31+
const [post, { isRefetching, refetch, mutate, error }] = useQuery<Post>(
32+
() => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
33+
)
34+
```
35+
36+
### Prevent Initial Fetching with `immediate: false`
37+
38+
```ts
39+
const [post, { isRefetching, refetch, mutate, error }] = useQuery<Post>(
40+
() => `https://jsonplaceholder.typicode.com/posts/${props.id}`,
41+
{ immediate: false }
42+
)
43+
```
1544

1645
## License
1746

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function injectQueryOptions(value?: TurboVueOptions) {
1818
* Creates a new query resource with the given key and options
1919
* for suspense usage.
2020
*/
21-
export async function createQueryResource<T = any>(
21+
export async function useAsyncQuery<T = any>(
2222
key: TurboVueKey,
2323
options?: TurboVueOptions,
2424
): Promise<TurboVueResource<T>> {

0 commit comments

Comments
 (0)