title: Promises in React native
body: <p>api/index.js</p>
  
  <pre><code>const URL = 'http://10.0.2.2:5000';
  const fetching = false;
  
  export default (type, filter, dateFilter, position) =&gt; {
      if(fetching) return Promise.reject(new Error('Request in progress'));
      fetching = true;
      return fetch(URL + `/search/${type}/${filter}/${dateFilter}/${position}/0/0`)
      .then(response =&gt; Promise.all([response, response.json()]))
      .catch(err =&gt; console.log("error catch search:", err.message))
  
  }
  </code></pre>
  
  <p>I need to put fetching false so in that way i can call this function again, but i dont know where to put it to make it work.
  If i create another then like this after the then writen and before the catch like this:</p>
  
  <pre><code>.then(() =&gt; fetching = false)
  </code></pre>
  
  <p>The problem is that it returns false to the place the function is called and NOT the data this is where is called:</p>
  
  <p>actions/index.js </p>
  
  <pre><code>getDataApi(type, filter, dateFilter, position)
     .then(res =&gt; {   
       if (res !== false) {         
           if (state.dataReducer.data.length === 0) {
               dispatch(getDataSuccess(res[1]))
           } else {
               dispatch(getDataSuccess(res[1], state.dataReducer.data))
           }       
      }
   })
  .catch((err) =&gt; console.log(9999, err))
  </code></pre>
  
  <p>So my problem is that it doesnt enter in the getDataSuccess because is false.I dont know why it cannot send the data to this function and it ends sending the result of fetching = false.</p>