You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Entirely rewrite server action for oRPC and comewith some utilities and
hooks for react
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced a dedicated React integration package that delivers
utilities for executing server actions and handling form submissions.
- Enabled experimental support in Next.js for enhanced authentication
handling.
- **Documentation**
- Updated guides and package overviews to highlight the new React
integration capabilities.
- **Chores**
- Refreshed dependencies and configurations for Next.js and React.
- **Tests**
- Expanded test coverage to validate the new integration utilities and
enhanced workflows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Copy file name to clipboardExpand all lines: README.md
+1
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
-[@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
-[@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
-[@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+
-[@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
-[@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
-[@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
-[@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
Copy file name to clipboardExpand all lines: apps/content/docs/server-action.md
+177-19
Original file line number
Diff line number
Diff line change
@@ -5,39 +5,36 @@ description: Integrate oRPC procedures with React Server Actions
5
5
6
6
# Server Action
7
7
8
-
[Server Action](https://react.dev/reference/rsc/server-functions) let client components call asynchronous server functions. With oRPC, you can make your procedures compatible by appending the `.actionable` modifier.
8
+
React [Server Actions](https://react.dev/reference/rsc/server-functions) let client components invoke asynchronous server functions. With oRPC, you simply append the `.actionable` modifier to enable Server Action compatibility.
9
9
10
10
## Server Side
11
11
12
-
Define your procedure using`.actionable`to enable Server Action compatibility. For example:
12
+
Define your procedure with`.actionable`for Server Action support.
context: async () => ({}), //Provide initial context if needed
24
+
context: async () => ({}), //Optional: provide initial context if needed
26
25
interceptors: [
27
-
onError((error) => {
28
-
console.error(error)
29
-
}),
30
-
]
26
+
onError(error=>console.error(error)),
27
+
],
31
28
})
32
29
```
33
30
34
31
:::tip
35
-
When using Server Actions, we recommend [Runtime Context](/docs/context#execution-context)over [Initial Context](/docs/context#initial-context).
32
+
We recommend using [Runtime Context](/docs/context#execution-context)instead of [Initial Context](/docs/context#initial-context) when working with Server Actions.
36
33
:::
37
34
38
35
## Client Side
39
36
40
-
On the client, simply import and call your procedure as shown below:
37
+
On the client, import and call your procedure as follows:
41
38
42
39
```tsx
43
40
'use client'
@@ -49,20 +46,181 @@ export function MyComponent() {
const { execute, data, error, status } =useServerAction(someAction, {
157
+
interceptors: [
158
+
onError((error) => {
159
+
if (isDefinedError(error)) {
160
+
console.error(error.data)
161
+
// ^ Typed error data
162
+
}
163
+
}),
164
+
],
165
+
})
166
+
167
+
const action =async (form:FormData) => {
168
+
const name =form.get('name') asstring
169
+
execute({ name })
170
+
}
171
+
172
+
return (
173
+
<formaction={action}>
174
+
<inputtype="text"name="name"required />
62
175
<buttontype="submit">Submit</button>
176
+
{status==='pending'&& <p>Loading...</p>}
63
177
</form>
64
178
)
65
179
}
66
180
```
67
181
68
-
This approach seamlessly integrates server-side procedures with your client components using Server Actions.
182
+
### `createFormAction` Utility
183
+
184
+
The `createFormAction` utility accepts a [procedure](/docs/procedure) and returns a function to handle form submissions. It uses [Bracket Notation](/docs/openapi/bracket-notation) to deserialize form data.
By moving the `redirect('/some-where')` logic into `createFormAction` rather than the procedure, you enhance the procedure's reusability beyond Server Actions.
223
+
224
+
::: info
225
+
When using `createFormAction`, any `ORPCError` with a status of `401`, `403`, or `404` is automatically converted into the corresponding Next.js error responses: [unauthorized](https://nextjs.org/docs/app/api-reference/functions/unauthorized), [forbidden](https://nextjs.org/docs/app/api-reference/functions/forbidden), and [not found](https://nextjs.org/docs/app/api-reference/functions/not-found).
Copy file name to clipboardExpand all lines: packages/arktype/README.md
+1
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
-[@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
-[@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
-[@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+
-[@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
-[@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
-[@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
-[@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
Copy file name to clipboardExpand all lines: packages/client/README.md
+1
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
-[@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
-[@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
-[@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+
-[@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
-[@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
-[@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
-[@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
Copy file name to clipboardExpand all lines: packages/contract/README.md
+1
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
-[@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
-[@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
-[@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+
-[@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
-[@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
-[@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
-[@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
Copy file name to clipboardExpand all lines: packages/openapi-client/README.md
+1
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
-[@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
-[@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
55
-[@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+
-[@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
57
-[@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
58
-[@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
59
-[@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
0 commit comments