0

How can i initialize mobx store and load data from my api server. I have to request an api server to get products data and put that data into the observable array. Then i will make computed functions to query over that array (ex. to get products by category name)

I already did some work but store will be initialized but my Flatlist items wont seen on app start. It just work after restart the app.

1 Answers1

0

Check out this simple mobx store with api call. Remember to define your api call function or import it accordingly.

// mobx Store
    class Store extends BaseStore {
      constructor() {
        super();
        this.getCustomers(); // initialize store observable
      }
    
      @observable customers = [];
      @action getCustomers = () => {
        this.customers = getList("customers"); // api call
        return this.customers;
      };
    }
Adam Beleko
  • 676
  • 7
  • 15