这是继电器变异的代码,我必须重新加载,因此存储将与数据库同步,因为由于某种原因,如果文本与先前添加的文本中继存储相同,则抛出错误flattenChildren ... < / p>
_handleTextInputSave = (text) => {
if(checkIfTextAlreadyExists(text) && window.confirm("Todo already exists! Please confirm to proceed.")) {
AddTodoMutation.commit(
this.props.relay.environment,
text,
this.props.viewer,
);
location.reload();
}
AddTodoMutation.commit(
this.props.relay.environment,
text,
this.props.viewer,
);
};
我无法想到其他方式,因为如果文本已经存在我必须重新加载但不知何故我觉得AddTodoMutation.commit是多余的。你怎么看?我很感激建议。
答案 0 :(得分:2)
看起来你总是想提交并且只是有条件地重新加载。所以写下:
_handleTextInputSave = (text) => {
const exists = checkIfTextAlreadyExists(text) && window.confirm("Todo already exists! Please confirm to proceed.");
AddTodoMutation.commit(
this.props.relay.environment,
text,
this.props.viewer,
);
if (exists)
location.reload();
};