i have a dynamic form and i save all values in one useState that name is formFieldsand output like this:
{
title: "aaa",
description: "bbb",
second_description: "ccc",
step_number: 1,
image: null,
},
{
title: "zzz",
description: "xxx",
second_description: "eee",
step_number: 2,
image: null,
}
]
i sholud save this array of objects and send as POST request like this:
{
steps: [
{
title: "aaa",
description: "bbb",
second_description: "ccc",
step_number: 1,
image: null,
},
{
title: "zzz",
description: "xxx",
second_description: "eee",
step_number: 2,
image: null,
}
]
}
but with this code i can't append this objects inside steps[]
formFields.forEach((item) => {
formData.append("steps[]", item);
});
and show me in console like this:
steps: Array [ "[object Object]", "[object Object]" ]
objects save like string in steps! , but i want to save object
how i can do that?
JSON.stringify| save like this :"{\"title\":\"aaaaaaaaaa\",\"description\":\"aaaaaaaaa\",\"second_description\":\"aaaaaaaaaaaaaaaaaaaaaaaaaa\",\"step_number\":1,\"image\":null}"