700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【react】This synthetic event is reused for performance reasons.

【react】This synthetic event is reused for performance reasons.

时间:2020-04-06 19:13:56

相关推荐

【react】This synthetic event is reused for performance reasons.

html代码

<form onSubmit={this.submit.bind(this)}><input type="text" name="username" value={this.state.username} onChange={this.change.bind(this)} /><input type="password" name="password" value={this.state.password} onChange={this.change.bind(this)} /><button>提交</button></form>

js代码

change(ev) {console.log(ev);}

错误截图

当我想访问ev.target的时候为null,且会报错

解决方案

change(ev) {ev.persist()console.log(ev);}

解决效果

问题原因

出于性能原因,将重用此合成事件。如果您看到这一点,那么您正在访问已释放/取消的合成事件的属性“target”。设置为空。如果必须保留原始合成事件,请使用event.persist()

有关更多信息,请参考。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。