# safe-action-hooks

A skill that tells your agent which next-safe-action hook fits a form or optimistic UI, and how to wire it to the server action.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1200 installs · ★ 1
- Author: next-safe-action
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/next-safe-action/skills/tree/HEAD/skills/safe-action-hooks/SKILL.md
- Updated: 2026-09-03
- HTML: https://affpapa.org/en/nevibecode/skills/safe-action-hooks

## What it does

The skill covers four hooks from `next-safe-action/hooks`: `useAction`, `useOptimisticAction`, `useStateAction` and `useOptimisticStateAction`. You pick by action kind first — `.action()` goes with the first two, `.stateAction()` with the other two. Each hook comes with a client component example: the `"use client"` directive, `onSuccess` and `onError` callbacks, a disabled button driven by `isPending`.

Queued writes get their own section. `useOptimisticStateAction` takes `currentState` and `updateFn`, then holds each dispatch until the previous one settles. The server sees the last confirmed state as `prevResult`. That matters for drag-to-reorder lists, Kanban boards, or any place where someone moves an item twice before the first save lands.

A few things will break it. `currentState` has to be a stable reference, because it is compared by identity. With `<form action={formAction}>` the server action must be a `.stateAction()`, and the input schema has to parse `FormData` — `zod-form-data` is the example given. The action also has to revalidate the state the page renders, otherwise the optimistic result drifts from what the page shows.

Install with `npx skills add` and the flag for your platform.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/safe-action-hooks/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/safe-action-hooks/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-hooks -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/safe-action-hooks/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-hooks -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/safe-action-hooks/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install next-safe-action/skills safe-action-hooks
```

2. **Manually: put the files in place**
- File: `.github/skills/safe-action-hooks/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-hooks -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/next-safe-action/skills --path skills/safe-action-hooks
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/safe-action-hooks/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-hooks -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/next-safe-action/skills/tree/HEAD/skills/safe-action-hooks/SKILL.md

## When to use it
- pick the right hook for an action kind
- make a checkbox toggle feel instant
- queue repeated reorders of a list item
- build a form on `<form action={formAction}>` that parses `FormData`
- surface a validation error next to its field

## Example prompts
- Pick the right next-safe-action hook for a feedback form
- Build a drag-to-reorder list with useOptimisticStateAction
- Why does my useOptimisticStateAction miss the previous state?

## Similar
- [react-hook-form-zod](https://affpapa.org/en/nevibecode/skills/react-hook-form-zod.md) — skill · 722 installs
- [formisch](https://affpapa.org/en/nevibecode/skills/formisch.md) — skill · 418 installs
- [nextjs-typescript-tailwindcss-supabase](https://affpapa.org/en/nevibecode/skills/nextjs-typescript-tailwindcss-supabase.md) — skill · 1300 installs
- [graphql-development](https://affpapa.org/en/nevibecode/skills/graphql-development.md) — skill · 661 installs
- [typescript-nextjs-supabase-cursorrules-prompt-file](https://affpapa.org/en/nevibecode/rules/typescript-nextjs-supabase-cursorrules-prompt-file.md) — rule · ★ 41011
- [tanstack-form](https://affpapa.org/en/nevibecode/skills/tanstack-form.md) — skill · 4300 installs

From the same set: [next-safe-action/skills](https://affpapa.org/en/nevibecode/by/next-safe-action/skills.md) — 2 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
