mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 20:53:08 +00:00
Error boundaries docs shouldn't use class fields
This commit is contained in:
@@ -150,14 +150,15 @@ React doesn't need error boundaries to recover from errors in event handlers. Un
|
||||
|
||||
If you need to catch an error inside event handler, use the regular JavaScript `try` / `catch` statement:
|
||||
|
||||
```js{8-12,16-19}
|
||||
```js{9-13,17-20}
|
||||
class MyComponent extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { error: null };
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
|
||||
handleClick = () => {
|
||||
handleClick() {
|
||||
try {
|
||||
// Do something that could throw
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user