diff --git a/docs/02-app/01-building-your-application/01-routing/05-error-handling.mdx b/docs/02-app/01-building-your-application/01-routing/05-error-handling.mdx index a2dc4be918fa4..fff77df1ed8ee 100644 --- a/docs/02-app/01-building-your-application/01-routing/05-error-handling.mdx +++ b/docs/02-app/01-building-your-application/01-routing/05-error-handling.mdx @@ -8,16 +8,18 @@ related: Errors can be divided into two categories: **expected errors** and **uncaught exceptions**: -- **Model expected errors as return values**: Avoid using `try`/`catch` for expected errors in Server Actions. Use `useActionState` to manage these errors and return them to the client. +- **Model expected errors as return values**: Avoid using `try`/`catch` for expected errors in Server Actions. Use [`useActionState`](https://react.dev/reference/react/useActionState) to manage these errors and return them to the client. - **Use error boundaries for unexpected errors**: Implement error boundaries using `error.tsx` and `global-error.tsx` files to handle unexpected errors and provide a fallback UI. +> **Good to know**: These examples use React's `useActionState` hook, which is available in React 19 RC. If you are using an earlier version of React, use `useFormState` instead. See the [React docs](https://react.dev/reference/react/useActionState) for more information. + ## Handling Expected Errors Expected errors are those that can occur during the normal operation of the application, such as those from [server-side form validation](/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-form-validation) or failed requests. These errors should be handled explicitly and returned to the client. ### Handling Expected Errors from Server Actions -Use the `useActionState` hook (previously `useFormState`) to manage the state of Server Actions, including handling errors. This approach avoids `try`/`catch` blocks for expected errors, which should be modeled as return values rather than thrown exceptions. +Use the [`useActionState`](https://react.dev/reference/react/useActionState) hook to manage the state of Server Actions, including handling errors. This approach avoids `try`/`catch` blocks for expected errors, which should be modeled as return values rather than thrown exceptions. ```tsx filename="app/actions.ts" switcher 'use server' diff --git a/docs/02-app/01-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx b/docs/02-app/01-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx index 1d747ce1b6a26..ecc79ffbf616f 100644 --- a/docs/02-app/01-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx +++ b/docs/02-app/01-building-your-application/02-data-fetching/03-server-actions-and-mutations.mdx @@ -288,7 +288,7 @@ This will trigger the submission of the nearest `