Hiya! ๐
I have a hard time triggering the error.tsx files in the app folder. I'm just trying to learn how it responds, but whenever I throw an error, or reject a promise, I just get a console log but no UI to show up.
The docs also don't tell me how errors are supposed to be triggered.
Any pointers on how to test this out?
Example:
// page.tsx
export default function Page() {
return (
<div>
<SomeComponent />
</div>
)
}
// SomeComponent.tsx
export default function SomeComponent() {
const [count] = useState(0)
return (
<div>
<p>Count: {count}</p>
<button onClick={() => { throw new Error('test')}}>Click</button>
</div>
)
}
// error.tsx
'use client'
import { useEffect } from 'react'
export default function Error({ error, reset }: { error: Error; reset: () => void }) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error)
}, [error])
return (
<div>
<h1>Whoops</h1>
<button onClick={() => reset()}>Try again</button>
</div>
)
}