Skip to content
Advertisement

React Native – Assign value from promise to variable

I have a couple repositories containing database calls such as getUser and getUsers. Now I export those repositories as followed:

JavaScript

This leads to me having to do things like this:

JavaScript

The intellisense says userRepository is:

JavaScript

Is there a way how to assign the functions to userRepository without me having to do any then calls on it? I’d like to just being able to call userRepository.getUser() for example.

Advertisement

Answer

You can use async/await instead of then.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement