Server Actions
Leverage oRPC for type-safe and powerful server actions
Introduction
oRPC makes it simple to implement server actions, offering a robust and type-safe way to manage server-side logic. Server actions are supported out of the box and are powered by several key features:
Requirements
To use a procedure as a server action, the procedure must either:
- Be directly callable, or
- Use Calling Procedures with Context to create a callable procedure with context.
Usage
Form Integration
Integrate server actions seamlessly with React forms for automatic type coercion:
Thanks to Smart Conversion, and Bracket Notation,
automatically convert 1992 into a bigint and seamlessly parse objects like user.
Direct Client Calls
Call server actions directly from client components for greater flexibility:
Server Actions with Context
Some procedures cannot be used as server actions directly. This is typically because they require additional context, such as user information or other runtime data. In such cases, you can use createProcedureCaller to provide the required context dynamically, making the procedure callable and usable as a server action.