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
Click on the number to increase the counter.
+The counter is programmed to throw an error when it reaches 5.
+