Back to React Router

useRouteError

docs/api/hooks/useRouteError.md

7.6.21.1 KB
Original Source

useRouteError

<!-- ⚠️ ⚠️ IMPORTANT ⚠️ ⚠️ Thank you for helping improve our documentation! This file is auto-generated from the JSDoc comments in the source code, so please edit the JSDoc comments in the file below and this file will be re-generated once those changes are merged. https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/hooks.tsx -->

[MODES: framework, data]

Summary

Reference Documentation ↗

Accesses the error thrown during an action, loader, or component render to be used in a route module ErrorBoundary.

tsx
export function ErrorBoundary() {
  const error = useRouteError();
  return <div>{error.message}</div>;
}

Signature

tsx
function useRouteError(): unknown

Returns

The error that was thrown during route loading, action execution, or rendering