diff --git a/examples/with-componentdidcatch/package.json b/examples/with-componentdidcatch/package.json index d06f8298..7cead30c 100644 --- a/examples/with-componentdidcatch/package.json +++ b/examples/with-componentdidcatch/package.json @@ -7,7 +7,7 @@ "start": "next start" }, "dependencies": { - "next": "6.0.0-canary.6", + "next": "latest", "react": "^16.0.0", "react-dom": "^16.0.0" }, diff --git a/examples/with-componentdidcatch/pages/index.js b/examples/with-componentdidcatch/pages/index.js index e9fd4786..cbc92c31 100644 --- a/examples/with-componentdidcatch/pages/index.js +++ b/examples/with-componentdidcatch/pages/index.js @@ -1,4 +1,30 @@ -export default () => { - // Render time error - throw new Error('Test') +import React, { Component } from 'react' + +class BuggyCounter extends Component { + state = { + counter: 0 + } + + handleClick = () => { + this.setState(({ counter }) => ({ + counter: counter + 1 + })) + } + + render () { + if (this.state.counter === 5) { + // Simulate a JS error + throw new Error('I crashed!') + } + + return

{this.state.counter}

+ } } + +export default () => ( +
+

Click on the number to increase the counter.

+

The counter is programmed to throw an error when it reaches 5.

+ +
+) diff --git a/examples/with-componentdidcatch/readme.md b/examples/with-componentdidcatch/readme.md index 5ec8b9b8..8d7cfd50 100644 --- a/examples/with-componentdidcatch/readme.md +++ b/examples/with-componentdidcatch/readme.md @@ -41,4 +41,4 @@ now ## The idea behind the example -This example shows how to catch errors caught by `componentDidCatch` in React's client side. +This example shows how to catch errors caught by `componentDidCatch` in React's **client** side.