React.js - input losing focus when rerendering

后端 未结 19 2006
猫巷女王i
猫巷女王i 2020-12-05 01:49

I am just writing to text input and in onChange event i call setState, so React rerenders my UI. The problem is that the text input always lose a f

19条回答
  •  粉色の甜心
    2020-12-05 02:15

    The core reason is: When React re-render, your previous DOM ref will be invalid. It mean react has change the DOM tree, and you this.refs.input.focus won't work, because the input here doesn't exist anymore.

提交回复
热议问题