0

我是新来的反应并构建一个页面,该页面从表单中获取详细信息并从输入的数据中将其显示在表格中。如果单击保存而不填写表格,它会显示错误,我认为这是因为如果保存它正在打印空箭头。 如果单击保存而不添加表单详细信息,则会引发错误

这是错误

const Subcontentinfo = () => {

    const [contacts, setContacts] = useState([
        { id: 1, firstname: "Mike", lastname: "Huston", surname: "MH", mailid: "mikehustoncorp@live.com", company: "Estra Boutique ltd." },
        { id: 2, firstname: "Richard", lastname: "", surname: "R", mailid: "mikehustoncorp@live.com", company: "Amazonia online" },
        { id: 3, firstname: "James", lastname: "Dustin", surname: "JD", mailid: "mikehustoncorp@live.com", company: "Alibaba Traders .co" },
        { id: 4, firstname: "Amanda", lastname: "Paul", surname: "AP", mailid: "mikehustoncorp@live.com", company: "Estra Boutique ltd." }
    ]);
 const [addFormData, setAddFormData] = useState({
        id: "",
        firstname: "",
        lastname: "",
        surname: "",
        mailid: "",
        company: "",
    });
const handleChange = (event) => {
        const fieldName = event.target.name;
        const fieldValue = event.target.value;

        setAddFormData({ ...addFormData, [fieldName]: fieldValue });

    }
  const handleSubmit = () =>{
 const newContact = {
                id: contacts.length + 1,
                firstname: addFormData.firstname,
                lastname: addFormData.lastname,
                surname: initialData(),
                mailid: addFormData.mailid,
                company: addFormData.company
            }

            setAddFormData({
                firstname: "",
                lastname: "",
                mailid: "",
                company: "",
            });

            setContacts([...contacts, newContact]);
}
const initialData2 = () => {
        let initial = addFormData.firstname.charAt(0) + addFormData.lastname.charAt(0);
        if (addFormData != "") {
            return initial;
        }
    }

我想我有这个功能错误

 **const initialData2 = () => {
        let initial = addFormData.firstname.charAt(0) + addFormData.lastname.charAt(0);
        if (addFormData != "") {
            return initial;
        }
    }**

有什么解决方案吗?

4

0 回答 0