I throw CustomError but error.tsx did not catch CustomError.
Answered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
await fetchSomething(); // throw CustomErrorimport { useEffect } from 'react'
import { CustomError } from "..."
export default function Error({
error,
reset,
}: {
error: CustomError & { digest?: string }
reset: () => void
}) {
useEffect(() => {
console.error(error) // did not catch CustomError, but catch Error
}, [error])
return (
<div>
//...
</div>
)
}umm... How to catch CustomError in error.tsx?
Is it possible?
Answered by Standard Chinchilla
Error.tsx only renders when there is an error on rendering the page on the server
3 Replies
Standard Chinchilla
Error.tsx only renders when there is an error on rendering the page on the server
Answer
Standard Chinchilla
What you have above is a client component, so what I would do is use useState to track the error. If there is an error set the errorState to true and return your error component if the errorState is true
Scaly-naped PigeonOP
Thankyou for answer