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.

func this.setState() error loop

See original GitHub issue

Hi, I use

<Tour
        steps={steps}
        isOpen={this.state.isTourOpen}
        onRequestClose={this.closeTour} 
        getCurrentStep={()=>this.setState({test:false})}
/>

or


{
    selector: '[data-tut="reactour__logo"]',
    content: `And this is our cool bus...`,
   action:()=>{ this.setState({test:false}) }
  },

In this.setState({test:false}) code , will report an error in the loop…

help me~~~

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zchuhuicommented, Sep 14, 2018

thanks, you are good man @elrumordelaluz

1reaction
elrumordelaluzcommented, Sep 14, 2018

Try doing something a little safer like:

    this.setState(prevState => {
      if (this.state.currentStep !== step) {
        return {
          currentStep: step
        };
      }
    });

However I am curious about the reason/s. Just to know if the API needs any improves.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why this setState caused infinite loop? - Stack Overflow
I created a react component with rendering call details, in component I use useEffect to set the callInfo state, then it caused infinite...
Read more >
How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >
React setState usage and gotchas - ITNEXT
setState() enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated...
Read more >
5 useEffect Infinite Loop Patterns | by Naveen DA
The function getData is passed as dependencies. When you run this code, it will throw Maximum update depth exceeded which means the code...
Read more >
How to Solve the Infinite Loop of React.useEffect()
1.1 Fixing dependencies ... The infinite loop is fixed by correct management of the useEffect(callback, dependencies) dependencies argument.
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