I have this data for prod
:
{
"0": {
prodName: "Tumbler",
price: 1.5,
size: "500",
colorMap: { Black: 20, Pink: 10, Green: 5 },
id: "aRLMZkiSU7T0lcsPCSsV"
},
"1": {
prodName: "Shirt",
price: 2,
size: "L",
colorMap: { Blue: 10, Black: 10 },
id: "uTHIR6OQFRuqP9Drft0e"
},
"2": {
prodName: "Shirt",
price: 2,
size: "L",
colorMap: { Blue: 10, Black: 10 },
id: "uTHIR6OQFRuqP9Drft0e"
}
};
I only want to retrieve the id of each of those products in the correct order and store it in my newOrder
How can I do this?
Codes:
const onSubmit = (data) => {
console.log(data, "d");
const newOrder = [];
data.order.forEach(({ product, variation }) => {
const newVariantion = [];
variation.forEach(({ qty, color }) => {
newVariantion.push({ qty: parseInt(qty), color });
});
newOrder.push({ product, variation: newVariantion });
});
actions.updateAction(data);
console.log(newOrder, "new order");
console.log(`Step1.prod = ${JSON.stringify(prod)}`);
navigate("/step2", newOrder);
};
Codesandbox: React Hook Form - Wizard Form - Getting the ID of each of the product - CodeSandbox