score:0

i highly doubt this simple solution will work, but here is my suggestions for refactors.

please note that the way that your old class was written, that's not the recommended way of writing redux. sure, the code will work, but it's not the "right" way in many people's opinions.

refactor your actions

i would rather have my code written out like this :

yourcomponent.tsx

const currentsite = useselector((state) =>      state.selection.currentsite);
   const currentcamera = useselector((state) => state.selection.currentcamera);
   const dispatch = usedispatch();

  const loadgraph = () => {
     useeffect(() => {
       if(currentsite)
          getfloorplan(currensite.identif);
      
     }, [ dispatch, currentsite.identif])
// dispatch is in the dependency array to stop make eslinter complain, you can remove it if you want, others are used to control the number of renders
    
  };

yourcomponentactions.ts

// assuming you are using redux-thunk here
const getfloorplan = ( site : yourtype ) => async dispatch => {
  console.log("fetched floorplan");
  // remove await if getimage is a sync function, try with await first and remove if it doesn't fit
  const response = await getimage(`api/graph/${site}/floorplan`, get_floorplan);
  dispatch(getgraph(response))
}

const getgraph = (site : yourtype) => async dispatch => {
   console.log("fetched model", realgraph.model);
   // new camera-related node & link status
   if (currentcamera) {
      changeactivecamera(currentsite.identif,currentcamera.identif);
   }
}

const changeactivecamera = ( site: yourtype, param: youranothertype ) => async dispatch => {
 // your logic here
}

Related Query

More Query from same tag