I have an endpoint that accept array of objects, but I don't know how to post the data based on user input using onChange. Here's my code
const [valuesInput, setValuesInput] = useState({
title: "",
question: [{ text: "", values: "" }],
category: "",
});
const data = new FormData();
data.append("feedback_title", valuesInput.title);
data.append("feedback_question", valuesInput.question);
data.append("kategori_feedback_id", valuesInput.category);
<input key={c} type="text" onChange={(e) => {setValuesInput({...valuesInput,question: [
{text: e.target.value,values: e.target.value,},],});}} />
the things that I want to achieve are like this code :
"data": [
{
"pertanyaan_feedback_id": 1,
"kategori_feedback_id": null,
"feedback_title": "test",
"feedback_question": [
{
"values": "dsfdsf",
"text": "vvfddf"
},
{
"values": "dsfdsf",
"text": "vvfddf"
},
{
"values": "dsfdsf",
"text": "vvfddf"
},
{
"values": "dsfdsf",
"text": "vvfddf"
}
],
"created_at": "2022-07-24T04:56:06.000000Z",
"updated_at": "2022-07-24T04:56:06.000000Z"
}
are there any suggestion what should I do to post array of object based on my code above? I'm very thankful if you want to give soe advice to solve my problem..