Skip to content

Instantly share code, notes, and snippets.

@Kola92
Last active February 21, 2023 14:34
Show Gist options
  • Save Kola92/4e8476bab0ab1be72ad864b83f09224b to your computer and use it in GitHub Desktop.
Save Kola92/4e8476bab0ab1be72ad864b83f09224b to your computer and use it in GitHub Desktop.
Error file that wrap a route segment with the React Error Boundary
app/dashboard/error.js directory
"use client"; // Error components must be Client components
import { useEffect } from "react";
export default function DashboardError({ error, reset }) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
}, [error]);
return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment