美文网首页
SyntheticEvent

SyntheticEvent

作者: 毛贵军 | 来源:发表于2018-11-01 15:43 被阅读0次

    在react 的事件中使用SyntheticEvent 就会出现下面的报错

    <input
      onChange={async e => {
        await foo()
        ...
    }}
    />
    

    Warning: 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 keep the original synthetic event around, use event.persist(). See https://fb.me/react-event-pooling for more information.

    那么怎么解决呢?

    <input
      onChange={async e => {
        e.persist()
        await foo()
        ...
    }}
    />
    

    详情可以看官方文档https://reactjs.org/docs/events.html

    相关文章

      网友评论

          本文标题:SyntheticEvent

          本文链接:https://www.haomeiwen.com/subject/bzrxxqtx.html