How can I push the product ID inside my variable newOrder

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

Hi Aranya,

Hope this helps you, but I can only offer this one observation.

It appears you get only one piece of information from the ordered item in your onSubmit method, for example product: "Notebook200".

The id for said notebook can be found in the prod state variable, however you’ll need to filter it out of the larger object.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.