【问题标题】:React losses input focus with many inputs反应损失输入焦点与许多输入
【发布时间】:2018-11-16 06:39:01
【问题描述】:

我已经为许多类似的案例尝试了几种做法,但没有一个适用于我的案例。输入一个字母后,表格的输入总是失去焦点。 如何避免?

我在 codesandbox.io 上的 sn-p 中提供了一个代码

链接:https://codesandbox.io/s/84wm4v4099

【问题讨论】:

    标签: reactjs input components state react-component


    【解决方案1】:

    问题在于每次调用 render 时您的键都会触发元素的完整重新渲染。 试试这个:

    return (
      <PTDR key={`input${idx}`}>
        <InputTable...
    

    See the working example here

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-08
    • 2017-08-06
    • 1970-01-01
    • 2021-01-29
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    相关资源
    最近更新 更多