Quantcast
Viewing all articles
Browse latest Browse all 1864

Refetch doesn't work in loop

Hi there,

I am trying to get all optionGroups with a given code in the array.
The refetch request runs only once and I cannot understand the reason.
request string defined as :

const queryOGs = {
    result: {
      resource: "optionGroups",
      params: ({ code }) => ({
        fields: ["id", "code", "options[id,name,code]"],
        filter: "code:like:" + code,
      }),
    },
  };

initial call:

const ogList = useDataQuery(queryOGs, {
    variables: { code: "RRR11111111" },
    onComplete: (response) => {
        if (response.result.optionGroups.length> 0)
          setOGList(response.result.optionGroups[0].options);
    },
  });

and refetch calls inside the loop:

 for (var j=0; j < childNode.length; j++){
   ogList.refetch({ code: childNode[j].value });
      if (OGList.length)
          OGList.map((e) => {
              some operations...
           })
}

It runs only once and the rest I can’t get any results…

Thank you
Regards,
Ulanbek

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 1864

Trending Articles