question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error Boundaries with shouldComponentUpdate method?

See original GitHub issue

I’m using this code from here: https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html

import React from "react";

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  componentDidCatch(error, info) {
    // Display fallback UI
    this.setState({ hasError: true });
    // You can also log the error to an error reporting service
    logErrorToMyService(error, info);
  }

  render() {
    if (this.state.hasError) {
      // You can render any custom fallback UI
      return <h1>Something went wrong.</h1>;
    }
    return this.props.children;
  }
}

and I got this error:

[eslint] Component is not optimized. Please add a shouldComponentUpdate method. (react/require-optimization).

What I should do?

I should add this?

shouldComponentUpdate() {
  return true;
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, May 29, 2018

I’d just disable the rule; i don’t know why we included it in the first place.

0reactions
ghostcommented, May 28, 2018

The rule is still there…

It disappear only if I put this:

  shouldComponentUpdate() {
    return true;
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Boundaries with shouldComponentUpdate method?
and I got this error: [eslint] Component is not optimized. Please add a shouldComponentUpdate method. (react/require-optimization).
Read more >
Error Boundaries - React
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI...
Read more >
How Error Boundaries work in React? - eduCBA
In react js the React Error Boundary allows us to handle errors, it helps our components from getting corrupt because of error in...
Read more >
ReactJS getDerivedStateFromError() Method - GeeksforGeeks
This method is used to implement the Error Boundaries for the React application. It is called during the render phase, so side-effects are...
Read more >
Working with React Components - Simple Talk
The ShouldComponentUpdate() lifecycle method has the following signature: ... An error boundary has the following lifecycle methods:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found