【问题标题】:unknown props message in console while using redux form使用 redux 表单时控制台中的未知道具消息
【发布时间】:2025-12-23 00:30:10
【问题描述】:

我在 react 应用程序中使用 redux 表单。我在渲染表单时在控制台中遇到此警告

warning: Unknown props `initialValue`, `autofill`, `onUpdate`, `valid`, `invalid`, `dirty`, `pristine`, `active`, `touched`, `visited`, `autofilled` on <input> tag. Remove these props from the element.

如何以 redux 形式解决此警告

【问题讨论】:

    标签: reactjs redux redux-form


    【解决方案1】:

    这个警告是introduced in React 15.2.0,以防止人们传递不必要或无效的道具。 Redux 表单这样做了,这可能就是您看到警告的原因。如果您想了解更多信息,请在 GitHub 上的问题跟踪器上找到 closed issue。它应该在this version 中修复,所以尝试更新,警告应该会消失。

    【讨论】:

      【解决方案2】:
      const renderField = field => (
        <div>
          <input {...field.input}/>
                       // ^^^^^^------------------ THAT is all you have to add. ?
          {field.touched && field.error && <span>{field.error}</span>}
        </div>
      )
      

      【讨论】:

      • 超级有用的缩写,只需要一些上下文和链接!