'React JS - How to update the existing data using form data?

I want to update existing image (which comes from MongoDB database) in React JS.

 const submitButton = async () =>{
    
    if(validForm()){

        Object.assign(userData,state)
       let url = `http://localhost:8080/users/update-user/${id}`

       const formData = new FormData();

       console.log("===",userData.profilePic)

       formData.append('name',userData.name);
       formData.append('email',userData.email);
       formData.append('myFile',userData.profilePic)
      
        try{
           let response = await axios.post(url, formData)
           console.log("inputField",formData);
           if(response.status == 200){
               toast.success("Updated Sucessfully");
               setTimeout(() => {
                navigate('/');
               }, 2000);
           }
       }
       catch(e){
            toast.error("Something went wrong..!");
       }
    }else{
        toast.error("Form Invalid..!");
    }
}

This is my controller code for UpdateDetails

const updateDetails = async (req,res) =>{
let user  =  await users.findById(req.params.id)
let response = await user;

const getData = {name: req.body.name, email: req.body.email}

user = Object.assign(response, getData);

user.save((err, savedUser)=>{
    if(err) {
        return (err)
    }

    res.json(savedUser.toJSON());
});
}

can we update existing data using formdata method in react js? or another techniques is there please let me know and also name and email also be update. Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source