javascript / intermediate
Snippet
Local Error Recovery with reset()
In App Router error segments, the reset function allows users to attempt recovery by re-rendering the route segment that failed, without forcing a full page reload.
snippet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
'use client';export default function Error({error,reset,}: {error: Error & { digest?: string };reset: () => void;}) {return (<div className="error-boundary"><h2>Something went wrong!</h2><button onClick={() => reset()}>Try again</button></div>);}
nextjs
Breakdown
1
reset: () => void;
A function that triggers a re-render of the specific route segment where the error occurred.
2
<button onClick={() => reset()}>
Provides a UI element for the user to manually trigger the recovery process.