import { ChangeDetectionStrategy, Component, inject } from '@angular/core' import { injectMutation, injectQuery, } from '@tanstack/angular-query-experimental' import { FormsModule } from '@angular/forms' import { DatePipe } from '@angular/common' import { TasksService } from '../services/tasks.service' @Component({ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'optimistic-updates', imports: [FormsModule, DatePipe], template: `
In this example, new items can be created using a mutation. The new item will be optimistically added to the list in hopes that the server accepts the item. If it does, the list is refetched with the true items from the list. Every now and then, the mutation may fail though. When that happens, the previous list of items is restored and the list is again refetched from the server.
Loading...
}Fetching in background
}