Files

28 lines
1.6 KiB
TypeScript

'use client';
/* The error state for every page: if a page throws while rendering, this replaces it (header and footer stay), sharing
the 404's halftone dot field. "Try again" re-renders the page; "Go home" leaves. Pages need nothing. */
import { useEffect, useRef } from 'react';
import { motion } from 'motion/react';
import Dots from '../components/Dots';
import { A } from '../components/kit';
import { EASE } from '../components/ui';
import '../components/pages/Lost.css';
export default function PageError({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
const host = useRef<HTMLElement>(null);
useEffect(() => { console.error(error); dispatchEvent(new CustomEvent('hz-event', { detail: { name: 'page_error', path: location.pathname, message: String(error?.message || '') } })); }, [error]);
const rise = (d: number) => ({ initial: { opacity: 0, y: 20 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.8, ease: EASE, delay: d } });
return (
<main ref={host} className="xlo" data-ask="off">
<Dots host={host} drift />
<section className="xlo-in x-wrap">
<h1 className="xlo-h1"><span className="x-line"><motion.span className="x-line-in" initial={{ y: '105%' }} animate={{ y: 0 }} transition={{ duration: 1.1, ease: EASE }}>This page didn&apos;t load.</motion.span></span></h1>
<motion.div className="xlo-acts" {...rise(0.3)}>
<button type="button" className="x-btn solid" onClick={() => reset()}>Try again</button>
<A to="/" className="x-btn">Go home</A>
</motion.div>
</section>
</main>
);
}