Running a SafeFn
As an action
When you're intending to call the SafeFn from the client, such as via a server action or through an API route, you can use the createAction()
method.
This returns a function that returns an ActionResult
. This is done as NeverThrow's Result
type cannot be serialized and sent to the client.
When using the useServerAction()
hook from safe-fn-react
, this is automatically converted back to a ResultAsync
for you.
The required argument is either the input type of the input schema if you defined one, or the type set through .unparsedInput<T>()
. This is merged that of the parent SafeFn if there is one.
Return type
See the dedicated page for the return type of createAction()
.