Skip to content
Back to skills

State Sync

ASecurity

Implements offline-first mobile state sync with optimistic updates and an MMKV offline queue; use when implementing offline-first features, handling optimistic updates, or building sync queues.

  • 19 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 19, 2026
ai-agentstypescriptreactapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 19, 2026

npx -y skills add sawrus/agent-guides --skill state-sync --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of State Sync?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for State Sync
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sawrus-state-sync/badge)](https://www.skillsdirectory.com/skills/sawrus-state-sync)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: state-sync
description: "Implements offline-first mobile state sync with optimistic updates and an MMKV offline queue; use when implementing offline-first features, handling optimistic updates, or building sync queues."
---

# Skill: Offline State Sync

## When to load

When implementing offline-first features, handling optimistic updates, or building sync queues.

## Optimistic Update Pattern

```typescript
const mutation = useMutation({
  mutationFn: api.createOrder,
  onMutate: async (newOrder) => {
    await queryClient.cancelQueries({ queryKey: ['orders'] });
    const previousOrders = queryClient.getQueryData<Order[]>(['orders']);
    queryClient.setQueryData<Order[]>(['orders'], (old = []) => [
      { ...newOrder, id: `temp_${Date.now()}`, _isOptimistic: true }, ...old
    ]);
    return { previousOrders };
  },
  onError: (_, __, context) => {
    queryClient.setQueryData(['orders'], context?.previousOrders);
    offlineQueue.enqueue({ type: 'CREATE_ORDER', payload: newOrder });
  },
});
```

## Offline Queue (MMKV)

```typescript
import { MMKV } from 'react-native-mmkv';
const storage = new MMKV({ id: 'offline-queue' });

export const offlineQueue = {
  enqueue(action) {
    const queue = this.getAll();
    storage.set('queue', JSON.stringify([...queue, { ...action, id: `action_${Date.now()}`, retryCount: 0 }]));
  },
  getAll(): QueuedAction[] {
    return JSON.parse(storage.getString('queue') ?? '[]');
  },
  async flush() {
    for (const action of this.getAll()) {
      try { await dispatch(action); this.remove(action.id); }
      catch { this.incrementRetry(action.id); }
    }
  },
};
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.