input's event.target is null within this.setState [React.js]

前端 未结 5 1862
暖寄归人
暖寄归人 2020-12-17 09:42

In my react component I have a file input:

` 

and my onFileChan

5条回答
  •  既然无缘
    2020-12-17 10:33

    The setState function is executed in asynchronous context.

    By the time the state is updated the e.target reference might or might not be gone.

    const file = e.target.files[0]; can be used to "remember" the value as in your example.

提交回复
热议问题