React-Native项目中出现报错:
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
翻译过来的意思就是:当component在componentWillUpdate
或componentDidUpdate时期内重复调用setState
时,就会发生超过最大递归深度这个问题。
为了说明白这件事,我先搞一张React-Native的生命周期函数。
说一下错误出现的背景:我们依托react-final-form
对表单的状态进行监控,并配合validation
进行表单的输入验证。在表单的输入过程中如果出现不符合要求的输入将会return error
,此时输入框下面的Button
按钮将会变成灰色不可用状态,当输入正确时,Button
的颜色将会是高亮显示为可用状态。
上代码截图:
在