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
Display Not Updating when using UseEffect()

I am trying to render an array of IP Addresses, after pushing each IP to an empty array. Once the array has been populated, I am able to see it correctly in the console, but for some reason, it refuses to show up on screen despite mapping it.

Variables:

var ipList = [];
let key = 0;
const [subnet, setSubnet]  = useState("");

This is the first useEffect which is supposed to trigger immediately when the component mounts. This is working fine.

useEffect(() =>  {
    const callNativeCode = async () => {
      await ConnectedDevices.displayConnectedDevices( (arrayResponse) => {setArray(arrayResponse), console.log("FIRST NATIVE CALL" + arr)}, (error) => {console.log(error)}  );
  }
  callNativeCode();
  },[]) 

This is the second useEffect which is supposed to populate the empty array with pingable IPs as soon as we get the subnet from the native java code. Also working fine and I get the array as I need it to be.

useEffect(() => {
      const ipLoop = async () => {

      if( subnet != "")
      {
        for(let i = 1; i<=254; i++)
        {
          let ipAddress = subnet + "." + i;
          try{
            const ip = await Ping.start(ipAddress, {timeout: 100});  
            const { receivedNetworkSpeed,sendNetworkSpeed,receivedNetworkTotal,sendNetworkTotal } = await Ping.getTrafficStats(ipAddress, {timeout:1000});
            console.log(ipAddress + " Network Stats: " + receivedNetworkSpeed,sendNetworkSpeed,receivedNetworkTotal,sendNetworkTotal);
            key = i;
            ipList.push(key , ipAddress);
          }
          catch(error) 
          {
            console.log(i + " Error Code:  " + error.code + " ," + error.message)
          }
        }
        renderIPList();
      }
    }
    ipLoop();

  },[subnet]);

And this is the render function that is supposed to display the array on screen. The log is working fine and I can see the array as intended. It just refuses to render.

  const renderIPList = () => {
    console.log("RENDERING IPS: ", ipList);
    return ipList.map((items,index) => {
      return (
        <View key={index}>
          <Text>{items}</Text>
        </View>
      );    
    });
  };

Thank you in advance for your help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change your ipList to be derived from useState like this:

const [ipList, setIpList] = useState([]);

and use the setIpList in your useEffect

and don't call renderIpList() as a function from useEffect that should be in the component return statement.

So, the useEffect should update the state, and then the component renders the state.

about 4 years ago · Juan Pablo Isaza Report
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!