2

Home Component

Data-Form Component

useInput Component

Table Component Output of Code (I can't add 3. row)

I would like to get input and put it table as table data. But ı can add only one triple data I cant add a second row. The second question is I would like to reset input boxes when I submit the form how could I do it.third question is how could ı make empty table at the beginning(I could not describe empty object). I dont need to save it on Json or any database ı just wanted to add when I open website. I mean it will be temporary data. Thank you for Helping :)

1 Answer 1

1
var inputData = []  //Global

const DataFormComponent = () => {
  const [formData, setFormData] = useState({data1: "", data2: "", data3:""})
  const handleSubmit = (event) => {
         event.preventDefault();
         setFormData({...formData, data1, data2, data3})  //spread operator and also duplicate properties in object gets assigned the new value         
         inputData.push(formData);
         console.log(inputData);
         setFormData({data1: "", data2: "", data3: ""}
  }

  return(
     <form onSubmit = {handleSubmit}>
        <input name = "data1" type = "txt"/>
        <input name = "data2" type = "txt"/>
        <input name = "data3" type = "txt"/>
        <button type = "submit">SUBMIT FORM</button>
      </form>
    )
  }

export default DataFormComponent
Sign up to request clarification or add additional context in comments.

5 Comments

I mean I get 3 input from my form and these 3 input directly going my table but if ı want add another inputs its not getting
You didn't find my solution helpful to your last 2 questions?
İts very useful sorry i didnt mention about it thank you :)
No problem buddy, I wish to help you further until you accept my answer.
You're not storing your inputs. Do this- Create an empty array and push the input values into this array and then you can console.log array values, Okay :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.