# 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.
* **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: 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://vytautaspranskunas.gitbook.io/react-state-rxjs/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.
