Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Error: Max update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate

I want to do in class component what I did in function component, but it gives an error. How can I fix?

function component:

const [listBtnClassName, setListBtnClassName] = useState("listBtnPulse");

useEffect(() => {
    if (showGrid) {
      setListBtnClassName("listBtnPulseNone");
    }
  }, [showGrid]);

<PageFilter listBtnClassName={listBtnClassName} ></PageFilter>

class component:

this.state = {
      listBtnClassName: "listBtnPulse",
    };

 componentDidUpdate() {
    if (this.props.showGrid) {
      this.setState({ listBtnClassName: "listBtnPulseNone" });
    }
  }

<PageFilter listBtnClassName={this.state.listBtnClassName} ></PageFilter>

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to make sure the showGrid from the previous props is not true, but the showGrid from current props is true.

See this document for more information.

this.state = {
  listBtnClassName: "listBtnPulse",
};

componentDidUpdate(prevProps) {
  if (!prevProps.showGrid && this.props.showGrid) {
    this.setState({ listBtnClassName: "listBtnPulseNone" });
  }
}
<PageFilter listBtnClassName={this.state.listBtnClassName} ></PageFilter>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!