'Get class object from a react component

I am trying to dynamically add markers to the here api map. I have an app that uses shodan and a geolocator to get the location of all ips connected to that IP. this is working fine.

My issue is updating a react component that is already loaded in react.

const map = <DisplayMapClass/>\\this is an atempt to save the object before it is called
  const asyncFunc = async () => {
      
      setLoading(true);
      const response = await fetch('http://68.71.131.14:5000/test/8.8.8.8'  );
      const data = await response.json();
      for(var x in data){
        addMarker(map, x["lat"], x["lng"])
      }
      setLoading(false)
  }
  
  \\if i can get the map object from the component i will be able to update the map
  const addMarker = (map, x, y) => {
    var marker =  new H.map.Marker({"lat": x, "lng": y})
    map.addObject(marker);
  } 

Above is the code attempt to make the changes it. the variable is considered undefined.

tldr; i need away of retrieving an object from a component.

bellow is a link to the repository.

https://github.com/frostWorks96/MapMyStalkers/



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source