title: How can I wait 5 second to send a HTTP request by Axios in React?
body: <p>I want to wait 3 second to return my value, but after I ran the function what I got was</p>
  <p>result</p>
  <p>then
  wait 3 seconds</p>
  <pre class="lang-js prettyprint-override"><code>function testFn() {
    setTimeout(() =&gt; console.log('wait 3 seconds'), 3000);
    return 'result';
  }
  
  testFn();
  </code></pre>
  <p>I want to wait 5 seconds to send the request if I got 'PEDING' from my first response,</p>
  <p>so I wrote a recursion function to do it, but it doesn't work</p>
  <p>it never wait 5 seconds then send the request.</p>
  <pre><code>  axios.post(&quot;api/A&quot;, searchInfo)
          .then(response =&gt; {
            if(response.data.message==='PENDING .'){
              const body={
              }
  
              setInterval(() =&gt; {
                console.log('wait 5 seconds first time')
            }, 5000);
            return APOSTRequest(body,dispatch,5000);
  
            }
      
          })
          .catch(err =&gt; {
            console.log(&quot;err&quot;, err);
  
          });
  
  
  const APOSTRequest=(body,dispatch)=&gt;{
  
    axios.post(&quot;api/A&quot;, body)
    .then(response =&gt; {
      if(response.data.message===&quot;PENDIG.&quot;){
        setInterval(() =&gt; {
          console.log('wait 5 seconds 2nd')
      }, 5000);
       return  setTimeout(APOSTRequest(body,dispatch), 5000);
      }else{
      }
    })
    .catch(err =&gt; {
      console.log(&quot;err&quot;, err);
    });
  
  }```
  </code></pre>