It returns undefinedbecause there is a path in which there is no instruction return. The template async-awaitworks great with asynchronous functions, but ActionSheetIOS.showActionSheetWithOptionsit is not async.
- , Promise. async - , , .
, , , async, Promise, :
function showActionSheetWithOptionsAsync(options) {
return new Promise(resolve => {
ActionSheetIOS.showActionSheetWithOptions(options, resolve);
});
}
async function _rescursiveSelect(data, index) {
if (index < data.length) {
const object = data[index];
if (object.array.length === 1) {
return await _rescursiveSelect(data, index + 1);
}
const buttonIndex = await showActionSheetWithOptionsAsync({
title: 'Choose a value from array: ',
options: object.array
});
const selectedValue = data[index].array[buttonIndex];
data[index].value = selectedValue;
delete data[index].array;
return await _rescursiveSelect(data, index + 1);
} else {
return data;
}
}