I'm totally newbie in JavaScript ... I have this code:
const MMKV = new MMKVStorage.Loader().initialize();
async function getData() {
let role = await MMKV.getStringAsync("role");
if (role === "distribuidor") {
consumerKey = Constants.Keys.distributorConsumerKey;
consumerSecret = Constants.Keys.distributorConsumerSecret;
return [consumerKey, consumerSecret];
}
};
let data = getData();
let consumerKey = data[0];
let consumerSecret = data[1];
export default {
WooCommerce: {
url: "https://xxxxx.com/",
consumerKey,
consumerSecret,
},
But consumerKey and consumerSecret are always undefined...
I know (I think) it's because the getData () function is asynchronous, and when I save the data in the variables, the function is not finished executing yet, but I don't know how to do it right. I have been quite a while, I have read about the callback functions, the promises, ... And I think the solution may go there, but I am very lost.
I would greatly appreciate a help. Thank you so much everyone.
Regards.