LogoIndieHub
icon of next-safe-action

next-safe-action

next-safe-action is a library for defining end-to-end typesafe and validated Server Actions in Next.js App Router projects.

Introduction

next-safe-action is a library designed to simplify the creation of type-safe server actions in Next.js applications using the App Router. It provides end-to-end type safety, ensuring that data passed between the client and server is consistent and validated. Key features include:

  • Type Safety: Leverages TypeScript to provide full type safety between client and server, reducing runtime errors.
  • Input/Output Validation: Supports multiple validation libraries for robust input and output validation, ensuring data integrity.
  • Form Actions Support: Seamlessly integrates with Next.js Form Actions, supporting both stateful and stateless actions.
  • Middleware System: Offers a powerful middleware system for managing authorization, logging, and other cross-cutting concerns.
  • Advanced Error Handling: Allows developers to customize how server errors are returned to the client and logged on the server.
  • Optimistic Updates: Includes a useOptimisticAction hook for implementing optimistic UI updates without waiting for server responses.

This library is ideal for developers looking to build robust, type-safe, and maintainable Next.js applications with server actions.