title: Why is my component in React being called multiple times?
body: <p>I am having an issue where my Listings component is running twice and I only want it to run once. I tried adding a counter below that would only run the code that grabs the data from the backend once but that did not work as you can see below it is still looping through the &quot;grabListings&quot; Function twice. I also tried a while loop and same result I am getting two results instead of one.</p>
  <p>I believe my issue has to do with the way I am calling the Listings component on my LandingPage.</p>
  <p>How can I run the grabListings component only once?</p>
  <p><strong>LandingPage</strong></p>
  <pre><code>    import NavBar from '../componets/NavBar/NavBar.js'
      import Footer from '../componets/Footer/Footer'
      import Slide1 from '../pictures/slide-1.jpg'
      import Listings from '../componets/Listings'
      import '../css/LandingPage.css';
      
      const LandingPage = () =&gt; {
      
          return (
              &lt;div className='wrapper'&gt;
                  &lt;NavBar /&gt;
      
                  &lt;div className='top-img'&gt;
                      &lt;img src={Slide1} alt='E46 Slide Show Pic 1' /&gt;
                  &lt;/div&gt;
      
                  &lt;Listings /&gt;
      
                  &lt;Footer /&gt;
              &lt;/div&gt;
      
          )
      }
      
      export default LandingPage
  </code></pre>
  <p><strong>Listings Component</strong></p>
  <pre><code>   const Listings = () =&gt; {
  
      let cars = []
      let links = []
      let prices = []
      let pictures = []
  
      let counter = 0
  
      const grabListings = async () =&gt; {
          
          if (counter &lt; 1) {
              try {
                  // console.log(&quot;looped thorugh grab listing&quot;)
                  await axios.get('http://localhost:5000/scrape').then(async (res) =&gt; {
                      console.log(&quot;looped thorugh grab listing&quot;);
                      console.log(res);
                      const carsData = await (await axios.get('http://localhost:5000/car')).data;
                      cars.push(carsData);
  
                      const linksData = await (await axios.get('http://localhost:5000/link')).data;
                      links.push(linksData);
  
                      const pricesData = await (await axios.get('http://localhost:5000/price')).data;
                      prices.push(pricesData);
  
                      const picturesData = await (await axios.get('http://localhost:5000/picture')).data;
                      pictures.push(picturesData);
  
                      counter++
                  });
              } catch (err) {
                  console.log(err);
                  counter++
              };
  
          };
  
          console.log(cars);
          console.log(links);
          console.log(prices);
          console.log(pictures);
      };
  
      grabListings();
  
  
  
      
  
      return (
          &lt;&gt;
              &lt;h1&gt;{cars[0]}&lt;/h1&gt;
          &lt;/&gt;
      )
  }
  
  export default Listings
  </code></pre>
  <p><strong>Result</strong>
  <a href="https://i.stack.imgur.com/59mRV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/59mRV.png" alt="enter image description here" /></a></p>