Unverified Commit 710997d4 authored by TodorTotev's avatar TodorTotev Committed by GitHub

refactor(with-sentry): example (#13434)

1. I updated all the packages.
2. Refactored the home component from class to functional
3. Example now uses getServerSideProps instead of getInitialProps
parent c01a93ad
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
}, },
"dependencies": { "dependencies": {
"@sentry/browser": "^5.0.3", "@sentry/browser": "^5.0.3",
"@sentry/node": "^5.0.3",
"@sentry/integrations": "^5.0.3", "@sentry/integrations": "^5.0.3",
"@sentry/node": "^5.0.3",
"@zeit/next-source-maps": "0.0.4-canary.1", "@zeit/next-source-maps": "0.0.4-canary.1",
"cookie-parser": "1.4.4", "cookie-parser": "1.4.4",
"express": "^4.16.4", "express": "^4.16.4",
"js-cookie": "2.2.0", "js-cookie": "2.2.0",
"next": "latest", "next": "latest",
"react": "^16.8.0", "react": "16.13.1",
"react-dom": "^16.8.0", "react-dom": "16.13.1",
"sentry-testkit": "^2.1.0", "sentry-testkit": "^2.1.0",
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },
......
import { Component } from 'react' import { useEffect, useState } from 'react'
import Link from 'next/link' import Link from 'next/link'
class Index extends Component { const Index = () => {
static getInitialProps({ query, req }) { const [state, setState] = useState({
if (query.raiseError) { raiseErrorInUseEffectHook: null,
throw new Error('Error in getInitialProps') })
}
}
state = { useEffect(() => {
raiseError: false, if (state.raiseErrorInUseEffectHook) {
} throw new Error('Error in useEffect Hook')
componentDidUpdate() {
if (this.state.raiseErrorInUpdate) {
throw new Error('Error in componentDidUpdate')
}
}
raiseErrorInUpdate = () => this.setState({ raiseErrorInUpdate: '1' })
raiseErrorInRender = () => this.setState({ raiseErrorInRender: '1' })
render() {
if (this.state.raiseErrorInRender) {
throw new Error('Error in render')
} }
}, [state.raiseErrorInUseEffectHook])
return ( return (
<div> <div>
<h2>Index page</h2> <h2>Index page</h2>
<ul> <ul>
<li> <li>
<a href="#" onClick={this.raiseErrorInRender}> <a
Raise the error in render href="#"
</a> onClick={() =>
</li> setState((current) => ({
<li> ...current,
<a href="#" onClick={this.raiseErrorInUpdate}> raiseErrorInUseEffectHook: '1',
Raise the error in componentDidUpdate }))
}
>
Raise the error in render or update
</a> </a>
</li> </li>
<li> <li>
<Link href={{ pathname: '/', query: { raiseError: '1' } }}> <Link href={{ pathname: '/', query: { raiseError: '1' } }}>
<a>Raise error in getInitialProps of client-loaded page</a> <a>Raise error in getServerSideProps</a>
</Link> </Link>
</li> </li>
<li>
<a href="/?raiseError=1">
Raise error in getInitialProps of server-loaded page
</a>
</li>
</ul> </ul>
</div> </div>
) )
}
export async function getServerSideProps({ query }) {
if (query.raiseError) {
throw new Error('Error in getServerSideProps')
}
return {
props: {},
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment