mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
45 lines
646 B
JavaScript
45 lines
646 B
JavaScript
'use client'
|
|
|
|
import { Component } from 'react'
|
|
|
|
class MyErrorBoundary extends Component {
|
|
static getDerivedStateFromError(error) {
|
|
return { error }
|
|
}
|
|
|
|
state = { error: null }
|
|
|
|
render() {
|
|
if (this.state.error) {
|
|
return 'failed'
|
|
}
|
|
return this.props.children
|
|
}
|
|
}
|
|
|
|
function Inner() {
|
|
return (
|
|
<MyErrorBoundary>
|
|
<Thrower />
|
|
</MyErrorBoundary>
|
|
)
|
|
}
|
|
|
|
function Thrower() {
|
|
useErrorHook()
|
|
}
|
|
|
|
function useThrowError() {
|
|
if (typeof window !== 'undefined') {
|
|
throw new Error('browser error')
|
|
}
|
|
}
|
|
|
|
function useErrorHook() {
|
|
useThrowError()
|
|
}
|
|
|
|
export default function Page() {
|
|
return <Inner />
|
|
}
|