Javascript formData不是react中的构造函数

Javascript formData不是react中的构造函数,javascript,arrays,reactjs,redux,Javascript,Arrays,Reactjs,Redux,user.js import React,{useState,useffect}来自“React”; 常量EditRekko=()=>{ const{id}=useParams(); const[rekko,setRekko]=useState({ 产品名称:“”, 类别ID:“”, 审查:'', 链接:“”, 用户id:“”, 产品名称:“” }); const[category,setCategory]=useState([]); const{product_name,categoryId,

user.js

import React,{useState,useffect}来自“React”;
常量EditRekko=()=>{
const{id}=useParams();
const[rekko,setRekko]=useState({
产品名称:“”,
类别ID:“”,
审查:'',
链接:“”,
用户id:“”,
产品名称:“”
});
const[category,setCategory]=useState([]);
const{product_name,categoryId,product_img,review,link,user_id}=rekko;
常量handleChange=e=>{
setRekko({…rekko[e.target.name]:e.target.value});
};
useffect(()=>{
loadRekko();
}, []);
常量handleImageChange=async e=>{
e、 预防默认值();
setRekko({…rekko[e.target.name]:e.target.files});
};
const handleSubmit=async e=>{
e、 预防默认值();
const formData=new formData();
//for(rekko.product\u img的常量文件){
//formData.append('product\u img',file)
// };
//formData.append('product_name',rekko.product_name)
//formData.append('review',rekko.review)
//formData.append('link',rekko.link)
//formData.append('categoryId',rekko.categoryId)
console.log(formData)
//等待Axios补丁(`http://localhost:3001/dashboard-rekko/${id}`,formData)
//toast.success(“Rekko更新”);
//setTimeout(函数(){
//history.push(“/rekko”)
// }, 1500);
};
返回(
handleSubmit(e)}>
产品名称:
handleChange(e)}/>
链接:
handleChange(e)}/>
产品图片:
handleImageChange(e)}/> 更新Rekko )
}

导出默认EditRekko


在提交时使用新表单数据发送时,我发现表单数据不是构造函数,我不知道主要问题是显示错误,如上所示,表单数据不是构造函数。我们将提供任何帮助,正如许多其他人所评论的,应该是:

import React, { useState, useEffect } from 'react';

const EditRekko = () => {
const { id } = useParams();
const [rekko, setRekko] = useState({
    product_name:'',
    categoryId:'',
    review:'',
    link:'',
    user_id:'',
    product_img:''
});
const [category, setCategory] = useState([]);

const { product_name, categoryId, product_img, review, link, user_id } = rekko;

const handleChange = e => {
    setRekko({ ...rekko, [e.target.name]: e.target.value });
};

useEffect(() => {
    loadRekko();
}, []);

const handleImageChange = async e => {
    e.preventDefault();
    setRekko({ ...rekko, [e.target.name]: e.target.files });
};

const handleSubmit = async e => {
    e.preventDefault();
    const formData = new formData();
    // for (const file of rekko.product_img) {
    //     formData.append('product_img', file)
    // };
    // formData.append('product_name', rekko.product_name)
    // formData.append('review', rekko.review)
    // formData.append('link', rekko.link)
    // formData.append('categoryId', rekko.categoryId)
    console.log(formData)
    // await Axios.patch(`http://localhost:3001/dashboard-rekko/${id}`, formData)
    // toast.success('Rekko Updated');
    // setTimeout(function () {
    //     history.push('/rekko')
    // }, 1500);

};

return (
    <>
        <form onSubmit={e => handleSubmit(e)} >
            <div className="form-group">
                <label htmlFor='product_name'>Product Name:</label>
                <input type="text" name="product_name" id="product_name" className="form-control" value={product_name || ''} onChange={e => handleChange(e)} />
            </div>
            <div className="form-group">
                <label htmlFor='link'>Link:</label>
                <input type="text" name="link" id="link" className="form-control" value={link || ''} onChange={e => handleChange(e)} />
            </div>
            <div className="form-group">
                <label htmlFor='product_img'>Product Image:</label> <br />
                <input type="file" multiple name="product_img" id="product_img" onChange={e => handleImageChange(e)} />
            </div>
            <button type="submit" className="btn btn-success"> Update Rekko </button>
        </form>
    </>
)

使用大写字母F
newformdata()
您的意思是
newformdata()
?注意大写字母
F
。JS是区分大小写的,我不知道什么是
formData
,但你必须在某个地方定义或导入它,否则你会有不同的错误。是的,它必须是大写字母,因为这是一个愚蠢的错误
// ...
const formData = new FormData();
// ...