Type safe Server Actions in your Next.js project
next-safe-action handles your Next.js app mutations type safety, input/output validation, server errors and even more!
$
pnpm add next-safe-action
"use server";
import { z } from "zod";
import { actionClient } from "./safe-action";
const inputSchema = z.object({
name: z.string().min(1),
});
export const greetAction = actionClient
.inputSchema(inputSchema)
.action(async ({ parsedInput: { name } }) => {
return {
message: `Hello, ${name}!`,
};
});
What developers are saying
Join thousands of developers who are already using next-safe-action in their projects
Try it out
See next-safe-action in action
Why choose next-safe-action?
A type-safe approach to handling Server Actions in your Next.js applications
Pretty simple
No need to overcomplicate things.
next-safe-action API is pretty simple, designed for the best possible DX.
next-safe-action API is pretty simple, designed for the best possible DX.
End-to-end type safe
With next-safe-action you get full type safety between server and client code.
Input/output validation
next-safe-action supports any validation library supported by Standard Schema. You can use Zod, Valibot, ArkType, and many more!
Powerful middleware system
Manage authorization, log and halt execution, and much more with a composable middleware system.
Advanced error handling
Decide how to return execution and validation errors to the client and how to log them on the server.
Form Actions support
next-safe-action supports Form Actions out of the box, with stateful and stateless actions.
Optimistic updates
Need to update UI immediately without waiting for server response? You can do it with the powerful
useOptimisticAction
hook.Integration with third party libraries
next-safe-action is designed to be extensible. You can easily integrate it with third party libraries, like react-hook-form.
Our sponsors
These amazing people and companies help keep next-safe-action running! โค๏ธ
Ready to get started?
Explore the documentation to learn how to use next-safe-action in your Next.js projects. Whether you're a beginner or already experienced with it, we've got you covered with comprehensive guides and examples.