【发布时间】:2018-11-24 22:23:09
【问题描述】:
我们从服务器获取一个允许用户编辑的表单,并使用 lodash _.set(object, path, value) 根据用户更新的表单部分更新该表单的部分内容。
我们试图通过设置组件内部的状态来获取当前值,但出现此错误;
Uncaught 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
我们的函数看起来像;
onChange = ({ form }) => {
const { path, editKeyword } = this.props;
const inputValue = form[editKeyword];
let prevForm = this.props.form;
// update the object using
const updatedForm = _.set(prevForm, path, inputValue);
// action
this.props.setCurrentForm(updatedForm); };
我们还尝试了以下方法,但没有成功:
onChange = ({ form }) => {
const { path, editKeyword } = this.props;
const inputValue = form[editKeyword];
console.log("input value ", inputValue);
let prevForm = this.props.form;
const updatedForm = _.set(prevForm, path, inputValue);
// when we try to update local state
this.setState({ form: updatedForm}) };
有没有人遇到过这种情况?
【问题讨论】:
标签: javascript reactjs redux state