Skip to content

Commit

Permalink
Add componentDidCatch example
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Apr 23, 2018
1 parent f48b67d commit 65c0014
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"babelrc": false
}
"presets": ["../babel"]
}
15 changes: 15 additions & 0 deletions examples/with-componentdidcatch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "hello-world",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "6.0.0-canary.6",
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"license": "ISC"
}
9 changes: 9 additions & 0 deletions examples/with-componentdidcatch/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from 'next/app'

export default class MyApp extends App {
componentDidCatch (error, errorInfo) {
console.log('CUSTOM ERROR HANDLING', error)
// This is needed to render errors correctly in development / production
super.componentDidCatch(error, errorInfo)
}
}
4 changes: 4 additions & 0 deletions examples/with-componentdidcatch/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default () => {
// Render time error
throw new Error('Test')
}

0 comments on commit 65c0014

Please sign in to comment.