1
- import { useParams , Link } from 'react-router'
1
+ import { useParams , Link , useRouteError } from 'react-router'
2
2
import { Button } from '#src/components/button.tsx'
3
3
import { Icon } from '#src/components/icon.tsx'
4
4
import data from '#src/data.json'
@@ -9,21 +9,7 @@ export function RecipientRoute() {
9
9
const { id } = useParams ( )
10
10
const recipient = recipients . find ( ( r ) => r . id === id )
11
11
12
- if ( ! recipient ) {
13
- return (
14
- < div className = "container mx-auto mt-4 flex flex-col gap-8" >
15
- < div className = "bg-danger-background rounded-sm p-4" >
16
- < p className = "text-danger-foreground" > Recipient not found</ p >
17
- </ div >
18
- < Link
19
- to = "/recipients"
20
- className = "text-link hover:text-link-hover block text-center hover:underline"
21
- >
22
- Back to recipients
23
- </ Link >
24
- </ div >
25
- )
26
- }
12
+ if ( ! recipient ) throw new Error ( `Recipient with ID of "${ id } " not found` )
27
13
28
14
return (
29
15
< div className = "flex min-h-0 flex-grow flex-col md:flex-row" >
@@ -164,3 +150,25 @@ export function RecipientRoute() {
164
150
</ div >
165
151
)
166
152
}
153
+
154
+ export function RecipientErrorBoundary ( ) {
155
+ const error = useRouteError ( )
156
+
157
+ return (
158
+ < div className = "container mx-auto mt-4 flex flex-col gap-8 px-8" >
159
+ < div className = "bg-danger-background rounded-sm p-4" >
160
+ < p className = "text-danger-foreground" >
161
+ { error instanceof Error ? error . message : 'Unknown error' }
162
+ </ p >
163
+ </ div >
164
+ < Link
165
+ to = "/recipients"
166
+ className = "text-link hover:text-link-hover block text-center hover:underline"
167
+ >
168
+ < Icon name = "ArrowLeft" className = "inline-block" >
169
+ Back to recipients
170
+ </ Icon >
171
+ </ Link >
172
+ </ div >
173
+ )
174
+ }
0 commit comments