Skip to content

Commit

Permalink
docs(general): 📘 update the README.md to reflect the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luii committed Oct 29, 2023
1 parent 1d602a0 commit 25d3467
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ export class TodosService {
private useQuery = inject(UseQuery);

getTodos() {
return this.useQuery(['todos'], () => {
return this.http.get<Todo[]>(
return this.useQuery({
queryKey: ['todos'],
queryFn: this.http.get<Todo[]>(
'https://jsonplaceholder.typicode.com/todos'
);
)
});
}

getTodo(id: number) {
return this.useQuery(['todo', id], () => {
return this.http.get<Todo>(
return this.useQuery({
queryKey: ['todo', id],
queryFn: () => this.http.get<Todo>(
`https://jsonplaceholder.typicode.com/todos/${id}`
);
)
});
}
}
Expand All @@ -108,14 +110,12 @@ export class TodosService {
Use it in your component:

```ts
import { SubscribeModule } from '@ngneat/subscribe';

@Component({
standalone: true,
imports: [NgIf, NgForOf, SpinnerComponent, SubscribeModule],
imports: [NgIf, NgForOf, AsyncPipe, SpinnerComponent],
template: `
<ng-container *subscribe="todos$ as todos">
<ng-query-spinner *ngIf="todos.isLoading"></ng-query-spinner>
<ng-container *ngIf="todos$ | async as todos">
<ng-query-spinner *ngIf="todos.isPending"></ng-query-spinner>
<p *ngIf="todos.isError">Error...</p>
Expand Down Expand Up @@ -146,20 +146,14 @@ export class ProjectsService {
private useInfiniteQuery = inject(UseInfiniteQuery);

getProjects() {
return this.useInfiniteQuery(
['projects'],
({ pageParam = 0 }) => {
return this.useInfiniteQuery({
queryKey: ['projects'],
queryFn: ({ pageParam = 0 }) => {
return getProjects(pageParam);
},
{
getNextPageParam(projects) {
return projects.nextId;
},
getPreviousPageParam(projects) {
return projects.previousId;
},
}
);
getNextPageParam: (projects) => projects.nextId,
getPreviousPageParam: (projects) => projects.previousId
});
}
}
```
Expand Down Expand Up @@ -245,7 +239,7 @@ import { QueryClientService, useMutationResult } from '@ngneat/query';
<button
(click)="addTodo({ title: ref.value })"
*subscribe="addTodoMutation.result$ as addTodoMutation"
*ngIf="(addTodoMutation.result$ | async) as addTodoMutation"
>
Add todo {{ addTodoMutation.isLoading ? 'Loading' : '' }}
</button>
Expand Down Expand Up @@ -306,7 +300,7 @@ And in the component:
<button
(click)="addTodo({ title: ref.value })"
*subscribe="addTodoMutation.result$ as addTodoMutation"
*ngIf="(addTodoMutation.result$ | async) as addTodoMutation"
>
Add todo {{ addTodoMutation.isLoading ? 'Loading' : '' }}
</button>
Expand Down

0 comments on commit 25d3467

Please sign in to comment.