ErrorBoundary components in Remix catch errors thrown in their child components during rendering, lifecycle methods, and constructors. When an error occurs, they render a fallback UI instead of crashing the whole app.
The ErrorBoundary component receives an object with an error property as props. To display the error message, you must use curly braces inside JSX to evaluate error.message.
Remix passes the error as a prop to the ErrorBoundary component. If the component does not accept the error prop, it cannot display or handle the error properly.
import { useState } from 'react'; export function ErrorBoundary({ error }) { const [hasError, setHasError] = useState(true); if (!hasError) { return <div>Try rendering child again.</div>; } return ( <div> <p>Error occurred: {error.message}</p> <button onClick={() => setHasError(false)}>Reset</button> </div> ); }
The useState hook manages local state inside the ErrorBoundary fallback UI. Clicking the button updates state to hide the error message and show alternative content.
ErrorBoundary components catch errors in their children and display fallback UI, improving user experience by preventing full app crashes.
