11import { withEmotionCache } from "@emotion/react" ;
2- import styled from "@emotion/styled" ;
32import type { MetaFunction } from "@remix-run/node" ;
43import {
54 Links ,
@@ -8,23 +7,22 @@ import {
87 Outlet ,
98 Scripts ,
109 ScrollRestoration ,
11- useCatch ,
10+ isRouteErrorResponse ,
11+ useRouteError ,
1212} from "@remix-run/react" ;
1313import { useContext , useEffect , useRef } from "react" ;
1414
1515import ClientStyleContext from "~/styles/client.context" ;
1616import ServerStyleContext from "~/styles/server.context" ;
1717
18- const Container = styled ( "div" ) `
19- background-color: #ff0000;
20- padding: 1em;
21- ` ;
2218
23- export const meta : MetaFunction = ( ) => ( {
24- charset : "utf-8" ,
25- title : "Remix with Emotion" ,
26- viewport : "width=device-width,initial-scale=1" ,
27- } ) ;
19+ export const meta : MetaFunction = ( ) => {
20+ return [
21+ { name : "title" , content : "Remix with Emotion" } ,
22+ { name : "viewport" , content : "width=device-width,initial-scale=1" } ,
23+ { name : "charset" , content : "utf-8" } ,
24+ ]
25+ }
2826
2927interface DocumentProps {
3028 children : React . ReactNode ;
@@ -94,26 +92,31 @@ export default function App() {
9492 ) ;
9593}
9694
97- export function CatchBoundary ( ) {
98- const caught = useCatch ( ) ;
95+ export function ErrorBoundary ( ) {
96+ const error = useRouteError ( ) ;
9997
100- return (
101- < Document title = { `${ caught . status } ${ caught . statusText } ` } >
102- < Container >
103- < p >
104- [CatchBoundary]: { caught . status } { caught . statusText }
105- </ p >
106- </ Container >
107- </ Document >
108- ) ;
109- }
98+ if ( isRouteErrorResponse ( error ) ) {
99+ return (
100+ < div >
101+ < h1 > Oops</ h1 >
102+ < p > Status: { error . status } </ p >
103+ < p > { error . data . message } </ p >
104+ </ div >
105+ ) ;
106+ }
107+
108+ // Don't forget to typecheck with your own logic.
109+ // Any value can be thrown, not just errors!
110+ let errorMessage = "Unknown error" ;
111+ if ( error instanceof Error ) {
112+ errorMessage = error . message ;
113+ }
110114
111- export function ErrorBoundary ( { error } : { error : Error } ) {
112115 return (
113- < Document title = "Error!" >
114- < Container >
115- < p > [ErrorBoundary]: There was an error: { error . message } </ p >
116- </ Container >
117- </ Document >
116+ < div >
117+ < h1 > Uh oh ... </ h1 >
118+ < p > Something went wrong. </ p >
119+ < pre > { errorMessage } </ pre >
120+ </ div >
118121 ) ;
119- }
122+ }
0 commit comments