In React ES6, why does the input field lose focus after typing a character?

前端 未结 10 2134
悲&欢浪女
悲&欢浪女 2020-12-08 12:54

In my component below, the input field loses focus after typing a character. While using Chrome\'s Inspector, it looks like the whole form is being re-rendered instead of ju

10条回答
  •  星月不相逢
    2020-12-08 13:35

    I am not authorised to comment then it must be an answer. I had similar issue and Answer from Alex Yan was corect.

    Namely I had that function

    const DisplaySearchArea =()=>{return (arrayOfSearchFieldNames.map((element, index)=>{return(
    {this.setState({ [element]: e.target.value }); console.log(e.target)}} onMouseEnter={e=>e.target.focus()}/>
    )}))}

    that behaves OK with FF and not with Chrome when rendered as When render as {...} it's OK with both. That is not so 'beaty' looking code but working, I have already been told to have tendency to overuse lambdas.

提交回复
热议问题