Search code examples
reactjsreactjs-fluxreact-native

reactjs/react-native wait for promise to resolve before proceeding


DB.users.get_all(function(response){
  this.setState(result: response); // not required
  return response // required but not working for react-native-db-model
});

Can i return response from this method. i am using react-native-db-model instead of setting response in setState() method. any other suggestion would be appreciated.

Thanks in Advance.


Solution

  • As far as I read the source code of react-native-db-models, function get_all is not returning anything, but just executing callback (https://github.com/darkrishabh/react-native-db-models/blob/master/index.js#L44)

    Therefore you can't return response to a variable. Thus, using setState() would be the best option IMO.