react Maximum update depth exceeded. This can happen when a component repeatedly calls...

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.

今天用react开发微信公众号的时候,竟然发生了如下错误?好吧!记录一下,避免以后再也不范这种低级错误。。。
react Maximum update depth exceeded. This can happen when a component repeatedly calls...

1.找出问题
ok,先找到发生错误的根源
react Maximum update depth exceeded. This can happen when a component repeatedly calls...
2.分析问题
这里的a标签是在一个循环里面的;
可以看见(我用红色框标记)onClick方法里面的this;
这样写的话这个this对象是指当前页面的对象;
而我们在循环里面一直调用go方法,
页面就会一直调用render(),导致页面一直在刷新
它就会一直给出很多个警告“Hash history cannot PUSH the same path; a new entry will not be added to the history stack”

3.解决方式
那么如何解决呢?其实也非常简单,只要在调用方法的时候的this对象不是当前页面的this对象就行了,而是只针对那个a标签;这样的话就不会一直render()了。ok,利用es6里面的语法就ojbk了:
react Maximum update depth exceeded. This can happen when a component repeatedly calls...