Skip to content

Commit 258238c

Browse files
authored
docs(angular-query): update examples and getting started docs (#6520)
1 parent e45c119 commit 258238c

File tree

14 files changed

+257
-384
lines changed

14 files changed

+257
-384
lines changed

docs/angular/devtools.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $ yarn add @tanstack/angular-query-devtools-experimental
1717

1818
You can import the devtools like this:
1919

20-
```typescript
20+
```ts
2121
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
2222
```
2323

@@ -27,7 +27,7 @@ Floating Mode will mount the devtools as a fixed, floating element in your app a
2727

2828
Place the following code as high in your Angular app as you can. The closer it is to the root of the page, the better it will work!
2929

30-
```typescript
30+
```ts
3131
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
3232
import { Component } from '@angular/core';
3333

docs/angular/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Installation
77
88
### NPM
99

10-
*Angular Query is compatible with Angular version 17.*
10+
_Angular Query is compatible with Angular version 17._
1111

1212
```bash
1313
$ npm i @tanstack/angular-query-experimental

docs/angular/overview.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,60 @@ title: Overview
77
88
The `@tanstack/angular-query-experimental` package offers a 1st-class API for using TanStack Query via Angular.
99

10-
## Feedback very welcome
10+
## Feedback welcome!
11+
1112
We are in the process of getting to a stable API for Angular Query. If you have any feedback, please contact us at the [TanStack Discord](https://tlinz.com/discord) server or [visit this discussion](https://github.com/TanStack/query/discussions/6293) on Github.
1213

1314
## Supported Angular Versions
15+
1416
Angular Query is compatible with Angular version 17.
1517

16-
## Example
18+
TanStack Query (FKA React Query) is often described as the missing data-fetching library for web applications, but in more technical terms, it makes **fetching, caching, synchronizing and updating server state** in your web applications a breeze.
19+
20+
## Motivation
21+
22+
Most core web frameworks **do not** come with an opinionated way of fetching or updating data in a holistic way. Because of this developers end up building either meta-frameworks which encapsulate strict opinions about data-fetching, or they invent their own ways of fetching data. This usually means cobbling together component-based state and side-effects, or using more general purpose state management libraries to store and provide asynchronous data throughout their apps.
23+
24+
While most traditional state management libraries are great for working with client state, they are **not so great at working with async or server state**. This is because **server state is totally different**. For starters, server state:
25+
26+
- Is persisted remotely in a location you do not control or own
27+
- Requires asynchronous APIs for fetching and updating
28+
- Implies shared ownership and can be changed by other people without your knowledge
29+
- Can potentially become "out of date" in your applications if you're not careful
30+
31+
Once you grasp the nature of server state in your application, **even more challenges will arise** as you go, for example:
32+
33+
- Caching... (possibly the hardest thing to do in programming)
34+
- Deduping multiple requests for the same data into a single request
35+
- Updating "out of date" data in the background
36+
- Knowing when data is "out of date"
37+
- Reflecting updates to data as quickly as possible
38+
- Performance optimizations like pagination and lazy loading data
39+
- Managing memory and garbage collection of server state
40+
- Memoizing query results with structural sharing
41+
42+
If you're not overwhelmed by that list, then that must mean that you've probably solved all of your server state problems already and deserve an award. However, if you are like a vast majority of people, you either have yet to tackle all or most of these challenges and we're only scratching the surface!
43+
44+
Angular Query is hands down one of the _best_ libraries for managing server state. It works amazingly well **out-of-the-box, with zero-config, and can be customized** to your liking as your application grows.
1745

18-
```typescript
46+
Angular Query allows you to defeat and overcome the tricky challenges and hurdles of _server state_ and control your app data before it starts to control you.
47+
48+
On a more technical note, Angular Query will likely:
49+
50+
- Help you remove **many** lines of complicated and misunderstood code from your application and replace with just a handful of lines of Angular Query logic.
51+
- Make your application more maintainable and easier to build new features without worrying about wiring up new server state data sources
52+
- Have a direct impact on your end-users by making your application feel faster and more responsive than ever before.
53+
- Potentially help you save on bandwidth and increase memory performance
54+
55+
[//]: # 'Example'
56+
57+
## Enough talk, show me some code already!
58+
59+
In the example below, you can see Angular Query in its most basic and simple form being used to fetch the GitHub stats for the TanStack Query GitHub project itself:
60+
61+
[Open in CodeSandbox](https://codesandbox.io/s/github/tanstack/query/tree/main/examples/angular/simple)
62+
63+
```ts
1964
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
2065
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
2166
import { HttpClient } from '@angular/common/http'
@@ -53,7 +98,7 @@ export class SimpleExampleComponent {
5398
queryKey: ['repoData'],
5499
queryFn: () =>
55100
lastValueFrom(
56-
this.http.get<Response>('https://api.github.com/repos/tannerlinsley/react-query')
101+
this.http.get<Response>('https://api.github.com/repos/tanstack/query'),
57102
),
58103
}))
59104
}
@@ -66,3 +111,7 @@ type Response = {
66111
forks_count: number
67112
}
68113
```
114+
115+
## You talked me into it, so what now?
116+
117+
- Learn Angular Query at your own pace with our amazingly thorough [Walkthrough Guide](../installation) and [API Reference](../reference/injectQuery)

docs/angular/quick-start.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@ If you're looking for a fully functioning example, please have a look at our [ba
1111

1212
### Provide the client to your App
1313

14-
```typescript
14+
```ts
1515
bootstrapApplication(AppComponent, {
1616
providers: [provideAngularQuery(new QueryClient())],
1717
})
1818
```
1919

2020
### Component with query and mutation
2121

22-
```typescript
22+
```ts
2323
import { Component, Injectable, inject } from '@angular/core'
2424
import { HttpClient } from '@angular/common/http'
2525
import { lastValueFrom } from 'rxjs'
2626

2727
import {
2828
injectMutation,
2929
injectQuery,
30-
injectQueryClient
30+
injectQueryClient,
3131
} from '@tanstack/angular-query-experimental'
3232

33-
3433
@Component({
3534
standalone: true,
3635
template: `
@@ -61,7 +60,7 @@ export class TodosComponent {
6160

6261
// OR use the queryClient that is injected into the component
6362
// this.queryClient.invalidateQueries({ queryKey: ['todos'] })
64-
}
63+
},
6564
}))
6665

6766
onAddTodo() {
@@ -72,22 +71,26 @@ export class TodosComponent {
7271
}
7372
}
7473

75-
@Injectable({providedIn: 'root'})
74+
@Injectable({ providedIn: 'root' })
7675
export class TodoService {
77-
private http = inject(HttpClient);
76+
private http = inject(HttpClient)
7877

7978
getTodos(): Promise<Todo[]> {
80-
return lastValueFrom(this.http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos'))
79+
return lastValueFrom(
80+
this.http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos'),
81+
)
8182
}
8283

8384
addTodo(todo: Todo): Promise<Todo> {
84-
return lastValueFrom(this.http.post<Todo>('https://jsonplaceholder.typicode.com/todos', todo))
85+
return lastValueFrom(
86+
this.http.post<Todo>('https://jsonplaceholder.typicode.com/todos', todo),
87+
)
8588
}
8689
}
8790

8891
interface Todo {
89-
id: string;
90-
title: string;
92+
id: string
93+
title: string
9194
}
9295
```
9396

examples/angular/basic/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"name": "@tanstack/query-example-angular-basic",
33
"private": true,
44
"type": "module",
5-
"version": "0.0.0",
6-
"description": "",
75
"scripts": {
86
"start": "vite",
97
"dev": "vite",
@@ -15,11 +13,9 @@
1513
"@angular/common": "^17.0.2",
1614
"@angular/compiler": "^17.0.2",
1715
"@angular/core": "^17.0.2",
18-
"@angular/language-service": "^17.0.2",
1916
"@angular/platform-browser": "^17.0.2",
20-
"@tanstack/angular-query-experimental": "^5.0.0",
21-
"@tanstack/angular-query-devtools-experimental": "^5.0.0",
22-
"axios": "^1.5.1",
17+
"@tanstack/angular-query-experimental": "^5.13.4",
18+
"@tanstack/angular-query-devtools-experimental": "^5.13.3",
2319
"rxjs": "^7.8.1",
2420
"zone.js": "^0.14.2"
2521
},

examples/angular/basic/public/emblem-light.svg

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)