formik in< input>标签

发布于 2025-02-03 08:11:48 字数 1333 浏览 0 评论 0 原文

我正在使用),但是当我呈现表格时,我会在浏览器上收到一些警告,说:

Warning: Invalid value for prop `value` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.

“在此处输入图像说明”

这就是我呈现我的字段的方式,

<FormGroup>
 <InputGroup>
  <InputLabel>
    {t('flightsCheckout.main.firstName')}
  </InputLabel>
  <Field name={`passengers[${index}].firstName`}>
    {({field}) => (
      <TextInput {...field} required
        placeholder="E.G. John (Given Name)" type="text"/>
    )}
  </Field>
 </InputGroup>
 <DottedLinesContainer>
  <DottedLines />
 </DottedLinesContainer>
 <InputGroup>
  <InputLabel>
    {t('flightsCheckout.main.lastName')}
  </InputLabel>
  <Field name={`passengers[${index}].lastName`}>
   {({ field }) => (
    <TextInput {...field} required placeholder="E.G. Smith (Last Name)" type="text"/>
   )}
  </Field>
 </InputGroup>
</FormGroup>

如何清除这些警告?

I'm building a form using Formik library on a NextJS project (Typescript), but when I render my form I get some warnings on the browser that say:

Warning: Invalid value for prop `value` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.

enter image description here

That's how I render my fields

<FormGroup>
 <InputGroup>
  <InputLabel>
    {t('flightsCheckout.main.firstName')}
  </InputLabel>
  <Field name={`passengers[${index}].firstName`}>
    {({field}) => (
      <TextInput {...field} required
        placeholder="E.G. John (Given Name)" type="text"/>
    )}
  </Field>
 </InputGroup>
 <DottedLinesContainer>
  <DottedLines />
 </DottedLinesContainer>
 <InputGroup>
  <InputLabel>
    {t('flightsCheckout.main.lastName')}
  </InputLabel>
  <Field name={`passengers[${index}].lastName`}>
   {({ field }) => (
    <TextInput {...field} required placeholder="E.G. Smith (Last Name)" type="text"/>
   )}
  </Field>
 </InputGroup>
</FormGroup>

how can I clear these warnings ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文