Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
React useeffect, callback function no response

I am trying to setState value from a callback function the problem is that the return BIM7AATypeComments sometimes is undefined but if I refresh the page it will add value to setState. I am not sure if I should use new Promise((resolve, reject)=>{}) however, I am using useEffect to fire the function. thanks!

//Get All Leavs Props
export const getAllLeavesProperties = (
  allModels: Autodesk.Viewing.GuiViewer3D | undefined,
  cb?
) => {
  const allLoadedViewers = isolateAndColorObject(
    allModels as Autodesk.Viewing.GuiViewer3D
  );
  return getAllLeavesDbId(allModels, (dbId: number[]) => {
    const count = dbId.length;
    dbId.forEach((id) => {
      if (allLoadedViewers && id) {
        for (let model of allLoadedViewers) {
          if (model)
            model.getProperties(id, (props) => {
              for (let prop of props.properties) {
                if (!prop) return;

                if (!histogram[prop.displayName]) {
                  histogram[prop.displayName] = {};
                }

                if (!histogram[prop.displayName][prop.displayValue]) {
                  histogram[prop.displayName][prop.displayValue] = [];
                }

                histogram[prop.displayName][prop.displayValue].push(props.dbId);
              }
            });
        }
      }
    });

    cb(histogram);
  });
};


const test = () => {
    if (!allModels) return;
    else {
      getAllLeavesProperties(allModels, (data: any[]) => { //callback 
        if (!data) return;
        //@ts-ignore
        const BIM7AATypeComments = data["BIM7AATypeComments"];
        if (BIM7AATypeComments) {
          try {
            //@ts-ignore
            const modelData = data["BIM7AATypeComments"];
            const label = Object.keys(modelData);

            console.log(label);
            if (label) setTt(label);
            //@ts-ignore
            const myObject = Object.keys(data["BIM7AATypeComments"]).map(
              //@ts-ignore
              (key) => data["BIM7AATypeComments"][key].length
            );
            if (myObject) setrr(myObject);
          } catch (error) {
            console.log(error);
          }
        }
      });
    }
  };
  
/*
  React.useEffect(() => {
    test();
  }, []);
  
*/

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda