oRPC is a powerful combination of RPC and OpenAPI, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
You can find the full documentation here.
Provides utilities for integrating oRPC with React and React Server Actions. Read the documentation for more information.
The useServerAction
hook simplifies invoking server actions in React.
'use client' import { isDefinedError, onError } from '@orpc/client' import { useServerAction } from '@orpc/react' export function MyComponent() { const { execute, data, error, status } = useServerAction(someAction, { interceptors: [ onError((error) => { if (isDefinedError(error)) { console.error(error.data) // ^ Typed error data } }), ], }) const action = async (form: FormData) => { const name = form.get('name') as string execute({ name }) } return ( <form action={action}> <input type="text" name="name" required /> <button type="submit">Submit</button> {status === 'pending' && <p>Loading...</p>} </form> ) }
Creates a form action that can be used in React forms and deserializes with bracket notation.
const dosomething = os .input( z.object({ user: z.object({ name: z.string(), age: z.coerce.number(), }), }) ) .handler(({ input }) => { console.log('Form action called!') console.log(input) }) export const redirectSomeWhereForm = createFormAction(dosomething, { interceptors: [ onSuccess(async () => { redirect('/some-where') }), ], }) export function MyComponent() { return ( <form action={redirectSomeWhereForm}> <input type="text" name="user[name]" required /> <input type="number" name="user[age]" required /> <button type="submit">Submit</button> </form> ) }
Distributed under the MIT License. See LICENSE for more information.
Share feedbackRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4