[英]React: How to debug why browser showing different value than HTML element in Chrome > Dev Tools?
I am building an app in react. 我正在构建一个反应应用程序。
Problem 问题
My app in Chrome browser is showing a different value than the corresponding HTML element in Dev Tools. 我在Chrome浏览器中的应用显示的值与开发工具中相应的HTML元素不同。 This only occurs after a user action on the UI to sort the table. 这仅在用户对UI进行表格排序操作之后发生。 It seems the browser is still showing the old value for that row in the table. 看来浏览器仍在表中显示该行的旧值。
See image below: 见下图:
Question 题
What steps should I take to diagnose what may be causing this issue? 我应该采取什么步骤来诊断可能导致此问题的原因?
eg is there somewhere I should add specific logs? 例如,我应该在哪里添加特定日志? or is this a known issue in react when someone is doing something clearly wrong? 还是当某人明显做错了事情时,这是一个已知的反应问题?
Note: This request is more about the how to diagnose such an issue, rather than finding what is specifically wrong with my code. 注意:此请求更多地是关于如何诊断这样的问题,而不是查找我的代码有什么特别错误。
The problem was in the code it seems. 问题是 ,似乎代码。 I found the cause through trial and error changing the code. 我通过反复尝试更改代码找到了原因。
Previously , the render for my component looked like: 以前 ,我组件的渲染看起来像:
render() {
return (
<td className="hoverWrapper">
<input
className="wrappedContent"
type="number"
onBlur={this.inputChangeHandler}
value={this.props.value}
></input>
<EditOnhoverbutton />
</td>
)
}
Changed to: 变成:
render() {
const showValue = this.props.value ? this.props.value : "";
return (
<td className="hoverWrapper">
<input
className="wrappedContent"
type="number"
onBlur={this.inputChangeHandler}
value={showValue}
></input>
<EditOnhoverbutton />
</td>
)
}
I suspect the underlying cause was related to the fact that for some rows this.props.value
did not exist, and trying to render undefined
caused the render to fail, and the original value continued to display. 我怀疑根本原因与以下事实有关:对于某些行, this.props.value
不存在,并且尝试渲染undefined
导致渲染失败,并且原始值会继续显示。
If anyone can provide a better assessment, I would be grateful. 如果有人能提供更好的评估,我将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.