2017-11-04 14:06:16 +00:00
|
|
|
import React from 'react'
|
2018-12-10 22:59:12 +00:00
|
|
|
import Link from 'next/link'
|
2017-11-04 14:06:16 +00:00
|
|
|
|
|
|
|
class Index extends React.Component {
|
2018-12-10 22:59:12 +00:00
|
|
|
static getInitialProps ({ query, req }) {
|
|
|
|
if (query.raiseError) {
|
|
|
|
throw new Error('Error in getInitialProps')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:51:35 +00:00
|
|
|
state = {
|
|
|
|
raiseError: false
|
2017-11-04 14:06:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 17:51:35 +00:00
|
|
|
componentDidUpdate () {
|
2018-12-10 22:59:12 +00:00
|
|
|
if (this.state.raiseErrorInUpdate) {
|
|
|
|
throw new Error('Error in componentDidUpdate')
|
2018-08-04 17:51:35 +00:00
|
|
|
}
|
2017-11-04 14:06:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 22:59:12 +00:00
|
|
|
raiseErrorInUpdate = () => this.setState({ raiseErrorInUpdate: '1' })
|
|
|
|
raiseErrorInRender = () => this.setState({ raiseErrorInRender: '1' })
|
2018-08-04 17:51:35 +00:00
|
|
|
|
2017-11-04 14:06:16 +00:00
|
|
|
render () {
|
2018-12-10 22:59:12 +00:00
|
|
|
if (this.state.raiseErrorInRender) {
|
|
|
|
throw new Error('Error in render')
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:06:16 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2>Index page</h2>
|
2018-12-10 22:59:12 +00:00
|
|
|
<ul>
|
|
|
|
<li><a href='#' onClick={this.raiseErrorInRender}>Raise the error in render</a></li>
|
|
|
|
<li><a href='#' onClick={this.raiseErrorInUpdate}>Raise the error in componentDidUpdate</a></li>
|
|
|
|
<li>
|
|
|
|
<Link href={{ pathname: '/', query: { raiseError: '1' } }}>
|
|
|
|
<a>Raise error in getInitialProps of client-loaded page</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href='/?raiseError=1'>
|
|
|
|
Raise error in getInitialProps of server-loaded page
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2017-11-04 14:06:16 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:51:35 +00:00
|
|
|
export default Index
|