diff --git a/examples/with-sentry/components/withSentry.js b/examples/with-sentry/components/withSentry.js deleted file mode 100644 index 4ffdb78d..00000000 --- a/examples/with-sentry/components/withSentry.js +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react' -import Raven from 'raven-js' - -const SENTRY_DSN = '' - -function withSentry (Child) { - return class WrappedComponent extends React.Component { - static getInitialProps (context) { - if (Child.getInitialProps) { - return Child.getInitialProps(context) - } - return {} - } - constructor (props) { - super(props) - this.state = { - error: null - } - Raven.config( - SENTRY_DSN - ).install() - } - - componentDidCatch (error, errorInfo) { - this.setState({ error }) - Raven.captureException(error, { extra: errorInfo }) - } - - render () { - return - } - } -} - -export default withSentry diff --git a/examples/with-sentry/pages/_app.js b/examples/with-sentry/pages/_app.js new file mode 100644 index 00000000..cfdb6658 --- /dev/null +++ b/examples/with-sentry/pages/_app.js @@ -0,0 +1,18 @@ +import App from 'next/app' +import Raven from 'raven-js' + +const SENTRY_PUBLIC_DSN = '' + +export default class MyApp extends App { + constructor (...args) { + super(...args) + Raven.config(SENTRY_PUBLIC_DSN).install() + } + + componentDidCatch (error, errorInfo) { + Raven.captureException(error, { extra: errorInfo }) + + // This is needed to render errors correctly in development / production + super.componentDidCatch(error, errorInfo) + } +} diff --git a/examples/with-sentry/pages/index.js b/examples/with-sentry/pages/index.js index ef09c018..826020e3 100644 --- a/examples/with-sentry/pages/index.js +++ b/examples/with-sentry/pages/index.js @@ -1,25 +1,26 @@ import React from 'react' -import withSentry from '../components/withSentry' class Index extends React.Component { - static getInitialProps (context) { - const { isServer } = context - return { isServer } + state = { + raiseError: false } - onClickHandler () { - throw new Error('woops') + componentDidUpdate () { + if (this.state.raiseError) { + throw new Error('Houston, we have a problem') + } } + raiseError = () => this.setState({ raiseError: true }) + render () { return (

Index page

- - +
) } } -export default withSentry(Index) +export default Index