控制台不显示我提供的文本输入
P粉419164700
P粉419164700 2024-04-04 20:30:28
[React讨论组]

所以我正在使用 formik 在 React 中构建一个表单。我制作了一个 TextInput 组件,其中包含一个进行了一些更改的输入字段。当我使用changeHandler时,它应该更新我输入的值,但事实并非如此。我想知道是否应该对 textInput 组件进行一些更改。

ContactForm.jsx

import React, { useState, useMemo } from "react";
import countryList from "react-select-country-list";
import { doc, setDoc, addDoc } from "firebase/firestore";
import { accountReqRef } from "../../Firebase";
import { useFormik } from "formik";

import Alert from "../../shared/components/UIElements/Alert";
import FormSelect from "../../shared/components/UIElements/FormSelect";
import TextInput from "../../shared/components/UIElements/TextInput";

const ContactForm = () => {
  const formik = useFormik({
    initialValues: {
      firstName: "",
      lastName: "",
      email: "",
      company: "",
      jobTitle: "",
      phone: "",
      country: "",
    },
  });

  const options = useMemo(() => countryList().getData(), []);

  const toast = (
    
New mail arrived.
Message sent successfully.
); // document submission date const current = new Date(); const date = `${current.getDate()}/${ current.getMonth() + 1 }/${current.getFullYear()}`; const accountReqDoc = { firstName: formik.values.firstName, lastName: formik.values.lastName, email: formik.values.email, company: formik.values.company, jobTitle: formik.values.jobTitle, phone: formik.values.phone, country: formik.values.country, subDate: date, status: "pending verification", }; console.log(formik); //add account request document to accountReq collection const addAccReq = () => { return
ContactForm
; }; /*const changeHandler = (country) => { setCountry(country); }; */ return (
First name Last name Email Confirm email
Your email address will be used to send the access credentials once your account creation request will be verified.
Company name Job title Phone number
); }; export default ContactForm;

TextInput.jsx

import React from "react";
import { BsInfoLg as InfoIcon } from "react-icons/bs";

const TextInput = (props) => {
  const isRequired = props.required;
  const infoText = props.info;
  return (
    
{ props.onChange(e.target.value); } : null } />
); }; export default TextInput;

P粉419164700
P粉419164700

全部回复(1)
P粉724256860

我的直觉是,您的输入要么缺少 idname

这是来自文档 https://formik.org/文档/api/formik#handlechange-e-reactchangeeventany--void

例如

这样想,handleChange怎么知道哪个字段正在更新。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号