From 65c0014ad174e5dcf3b991cfacd9c91edb3972d4 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 23 Apr 2018 14:22:36 -0700 Subject: [PATCH] Add componentDidCatch example --- examples/.babelrc | 4 ++-- examples/with-componentdidcatch/package.json | 15 +++++++++++++++ examples/with-componentdidcatch/pages/_app.js | 9 +++++++++ examples/with-componentdidcatch/pages/index.js | 4 ++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 examples/with-componentdidcatch/package.json create mode 100644 examples/with-componentdidcatch/pages/_app.js create mode 100644 examples/with-componentdidcatch/pages/index.js diff --git a/examples/.babelrc b/examples/.babelrc index 6714336e..2b5be340 100644 --- a/examples/.babelrc +++ b/examples/.babelrc @@ -1,3 +1,3 @@ { - "babelrc": false -} \ No newline at end of file + "presets": ["../babel"] +} diff --git a/examples/with-componentdidcatch/package.json b/examples/with-componentdidcatch/package.json new file mode 100644 index 00000000..a2f3b1c6 --- /dev/null +++ b/examples/with-componentdidcatch/package.json @@ -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" +} diff --git a/examples/with-componentdidcatch/pages/_app.js b/examples/with-componentdidcatch/pages/_app.js new file mode 100644 index 00000000..a2af3633 --- /dev/null +++ b/examples/with-componentdidcatch/pages/_app.js @@ -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) + } +} diff --git a/examples/with-componentdidcatch/pages/index.js b/examples/with-componentdidcatch/pages/index.js new file mode 100644 index 00000000..e9fd4786 --- /dev/null +++ b/examples/with-componentdidcatch/pages/index.js @@ -0,0 +1,4 @@ +export default () => { + // Render time error + throw new Error('Test') +}