Maximum call stack size exceeded - Connected React Component

后端 未结 1 1865
甜味超标
甜味超标 2020-12-11 11:05

I can\'t for the life of me figure out why I\'m getting error:

Maximum call stack size exceeded

When this code is run. If I com

相关标签:
1条回答
  • 2020-12-11 11:30

    Because of this loop:

      render  ----->   getTabs  ----->  setState -----
        ^                                            |
        |                                            |
        |____________________________________________v
    

    You are calling getTabs method from render, and doing setState inside that, setState will trigger re-rendering, again getTabs ..... Infinite loop.

    Remove setState from getTabs method, it will work.

    Another issue is here:

    onclick={this.tabChanged(idx, headline)}
    

    We need to assign a function to onClick event, we don't need to call it, but here you are calling that method, use this:

    onclick={() => this.tabChanged(idx, headline)}
    
    0 讨论(0)
提交回复
热议问题