1,791   Reactjs

一,现象
在添加输入框时,发现每次输入内容改变后,输入框都会失去焦点

 

二,原因
因为没有给输入框定义唯一的 key 导致每次更改 input 内容后,重新渲染 render 时,会创建新的 input 节点,所以就丢失了焦点

 

三,方法
给 input 添加唯一不变的 key 即可

 

更多资料
http://stackoverflow.com/questions/22573494/react-js-input-losing-focus-when-rerendering




Leave a Reply

Your email address will not be published. Required fields are marked *