<Input placeholder="请输入联系人姓名" maxLength={50} allowClear onChange={onChange} /> const onChange = (e) => { console.log(e) }运行后,出现了下面的错误:
This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `target` on a released/nullified synthetic event. This is set to null. If you must... ...
原因是,出于性能原因,将重用此合成事件。如果您看到这一点,那么您正在访问已释放/取消的合成事件的属性“target”。设置为空。如果必须保留原始合成事件,请使用event.persist()。有关更多信息,请参见https://fb.me/react-event-pooling
解决办法:
const onChange = (e) => { e.persist(); setNameLength(e.target.value.length); };