Last active
February 21, 2023 14:34
-
-
Save Kola92/4e8476bab0ab1be72ad864b83f09224b to your computer and use it in GitHub Desktop.
Error file that wrap a route segment with the React Error Boundary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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