Skip to main content
skill CX Codex

safe-action-hooks — Claude Code skill for next-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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code
Open on GitHub

What safe-action-hooks 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.

What it helps with

  • 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 for the agent

  • 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?

How to install safe-action-hooks

1Skills CLI (Vercel)

npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code

2Manually: put the files in place

~/.claude/skills/safe-action-hooks/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/safe-action-hooks/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about safe-action-hooks

How do I install safe-action-hooks in Claude?

Run npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code. The skill lands at ~/.claude/skills/safe-action-hooks/SKILL.md.

What does safe-action-hooks do?

It tells your agent which next-safe-action hook to use and how to connect it to a server action. It documents useAction, useOptimisticAction, useStateAction and useOptimisticStateAction.

How is useOptimisticAction different from useOptimisticStateAction?

The first suits changes that replace state outright. The second handles accumulating edits: dispatches are queued and each one folds over the confirmed state.

Similar skills

Everything for Frontend and UI →

From the same set2

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor