skip to Main Content

this is the form component that was not resettin or custom changing after submitting the form
[this is the item list component (https://i.stack.imgur.com/nIuLB.png) ][this is form output after submitting a item (https://i.stack.imgur.com/OChL5.png)] I really dont seem understand why setformdata works for onchange event but not for the onsubmit event

3

Answers


  1. useState is asynchronous. A workaround to get the effect you want is by using useEffect hook and adding the variable to the dependency array

    useEffect(()=>{
    
    //some code here
    
    },[formData])
    
    Login or Signup to reply.
  2. You should set value of input that named "product" :

    <input name='product' value={formData.product} ...//rest attributes /> 
    

    And

    <input name='quality' value={formData.quality} ...//rest attributes /> 
    
    Login or Signup to reply.
  3. In the input field u need to set the value of formData

    <input 
    type="text"
    placeholder = "prduct name"
    value= {formData.product}
    onChange={handleChange}
    />
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search