Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!