> For the complete documentation index, see [llms.txt](https://vytautas.gitbook.io/ng-state/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vytautas.gitbook.io/ng-state/core-concepts/store/optimistic-updates-plugin.md).

# Optimistic updates plugin

In order to make UI feel like native we need to performa optimistic updates. But these updates comes with price of reverting state if something went wrong during API calls. This plugin helps to solve this.

```typescript
this.store.optimisticUpdates.revertLastChanges(2);
```

#### API:

* **tagCurrentState(tag: string)** - you can tag current state to know where to revert to.&#x20;
* **revertToTag(tag: string)** - revert state to tag in case of failure
* **revertToLastTag()** - revert to last tag available
* **revertLastChanges(count: number)** - revert N changes

> Remember that root level store reverts whole state while nested (actions) level store reverts only state that it is responsible for!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vytautas.gitbook.io/ng-state/core-concepts/store/optimistic-updates-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
