Search code examples
reactjsreact-nativewoocommercewordpress-rest-apiwoocommerce-rest-api

Get all products woocommerce rest api react native


I am trying build search function in my react native app to search in my woocommerce products (1000 products aprox)

here is my code

componentDidMount() {
let p=1;
    
    while (p<11)
    {console.log(p)
    WooCommerce.get("products",{per_page:100,page:p})
    .then((response) => {
      p++;
      allprod = allProd.concat(response)

    }
    

    )
    .catch((error) => {
      console.log(error.response);
    });
  }

i am getting this error ExceptionsManager.js:173 Warning: Please report: Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native code: {"1623":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"1865":{"module":"Networking","method":"sendRequest"},"1872":{"module":"Networking","method":"sendRequest"},"1879":{"module":"Networking","method":"sendRequest"},"1886":{"module":"Networking","method":"sendRequest"},"1893":

anyone have an idea about what i am doing wrong?? you help is much appreciated


Solution

  • Why do you need to fetch all the data on componentDidMount() ? And if so why don’t you simply fetch everything in one call( per_page:1000) ?

    What happens here is that your while will run over and over again. WooCommerce.get is async so it wont wait until you increase p. If you still want to keep thing like this you could try to change that while in a for.